|
| 1 | +name: Publishing |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + source_branch: |
| 10 | + description: 'Source branch' |
| 11 | + required: true |
| 12 | + default: 'main' |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + publish: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v3 |
| 23 | + with: |
| 24 | + ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_branch || github.ref }} |
| 25 | + submodules: recursive |
| 26 | + |
| 27 | + - name: Check if should be published |
| 28 | + if: ${{ github.event_name != 'workflow_dispatch' && !contains(github.event.head_commit.message, '[pub]') }} |
| 29 | + run: | |
| 30 | + echo "[pub] string is missing in commit message, skipping ..." |
| 31 | + exit 0 |
| 32 | +
|
| 33 | + - name: Publish |
| 34 | + id: pub |
| 35 | + if: ${{ github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '[pub]') }} |
| 36 | + run: | |
| 37 | + echo "::group::Copy _invariant to all language directories, package them" |
| 38 | + SRC_DIR="_invariant" |
| 39 | + mkdir -p $SRC_DIR |
| 40 | + mkdir -p _output |
| 41 | + echo "::endgroup::" |
| 42 | + |
| 43 | + for dir in */ ; do |
| 44 | + dir=${dir%/} |
| 45 | + echo "::group::Language: $dir" |
| 46 | +
|
| 47 | + case "$dir" in |
| 48 | + _*) continue ;; |
| 49 | + esac |
| 50 | +
|
| 51 | + echo "Copying language invariant data ..." |
| 52 | + cp -r -T -v "$SRC_DIR"/. "$dir"/ |
| 53 | + cd $dir |
| 54 | + echo "Zipping ..." |
| 55 | + zip -r -9 ../_output/Help-$dir.zip . |
| 56 | + cd .. |
| 57 | + echo "Language: $dir done." |
| 58 | + echo "::endgroup::" |
| 59 | + done |
| 60 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 61 | + echo "Bundling finished." |
| 62 | +
|
| 63 | + - name: Create tag |
| 64 | + id: newtag |
| 65 | + if: steps.pub.outputs.exists == 'true' |
| 66 | + run: | |
| 67 | + echo "::group::Version overview" |
| 68 | + VERSION=$(awk '/^## /{print $2; exit}' CHANGELOG.md) |
| 69 | + BODY=$(awk '/^## /{if (seen++) exit} seen' CHANGELOG.md | tail -n +2) |
| 70 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 71 | + echo "body<<EOF" >> $GITHUB_OUTPUT |
| 72 | + echo "$BODY" >> $GITHUB_OUTPUT |
| 73 | + echo "EOF" >> $GITHUB_OUTPUT |
| 74 | + echo "::endgroup::" |
| 75 | + |
| 76 | + TAG="$VERSION" |
| 77 | +
|
| 78 | + echo "::group::Old release delete" |
| 79 | + RELEASE_ID=$(curl -s -H "Authorization: token $TOKEN" \ |
| 80 | + https://api.github.com/repos/$REPO/releases/tags/$TAG | jq -r .id) |
| 81 | +
|
| 82 | + if [ "$RELEASE_ID" != "null" ]; then |
| 83 | + echo "Deleting release ID $RELEASE_ID" |
| 84 | + curl -s -X DELETE -H "Authorization: token $TOKEN" \ |
| 85 | + https://api.github.com/repos/$REPO/releases/$RELEASE_ID |
| 86 | + fi |
| 87 | + echo "::endgroup::" |
| 88 | + |
| 89 | + echo "::group::Old tag delete" |
| 90 | + if git ls-remote --tags origin | grep -q "$TAG"; then |
| 91 | + git tag -d "$TAG" || true |
| 92 | + git push origin ":refs/tags/$TAG" || true |
| 93 | + fi |
| 94 | + echo "::endgroup::" |
| 95 | +
|
| 96 | + echo "::group::New tag created" |
| 97 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 98 | + git tag $TAG |
| 99 | + git push origin $TAG || true |
| 100 | + echo "::endgroup::" |
| 101 | + |
| 102 | + - name: Create release |
| 103 | + id: crelease |
| 104 | + if: steps.pub.outputs.exists == 'true' |
| 105 | + uses: actions/create-release@v1 |
| 106 | + with: |
| 107 | + tag_name: ${{ steps.newtag.outputs.tag }} |
| 108 | + release_name: ${{ steps.newtag.outputs.tag }} |
| 109 | + body: ${{ steps.newtag.outputs.body }} |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ secrets._TOKEN }} |
| 112 | + |
| 113 | + - name: Upload helps for languages |
| 114 | + if: steps.pub.outputs.exists == 'true' |
| 115 | + env: |
| 116 | + GITHUB_TOKEN: ${{ secrets._TOKEN }} |
| 117 | + TAG: ${{ steps.newtag.outputs.tag }} |
| 118 | + REPO: ${{ github.repository }} |
| 119 | + run: | |
| 120 | + cd _output |
| 121 | + echo "$TAG" >> _version.txt |
| 122 | + echo "$REPO" >> _prjname.txt |
| 123 | + |
| 124 | + find . -type f -name "*.zip" -print0 | while IFS= read -r -d '' file; do |
| 125 | + echo "Language bundle to upload: $file" |
| 126 | + zip -u "$file" _version.txt _prjname.txt |
| 127 | + gh release upload "$TAG" "$file" --repo "$REPO" --clobber |
| 128 | + done |
0 commit comments