|
| 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: Clone another repo into folder xxx |
| 34 | + env: |
| 35 | + TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + run: | |
| 37 | + mkdir -p _ftsbuilder |
| 38 | + git clone https://x-access-token:${TOKEN}@github.com/HelpViewer/fulltextSearchDBBuilder.git _ftsbuilder |
| 39 | +
|
| 40 | + - name: Publish |
| 41 | + id: pub |
| 42 | + if: ${{ github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '[pub]') }} |
| 43 | + run: | |
| 44 | + echo "::group::Copy _invariant to all language directories, package them" |
| 45 | + mkdir -p _output |
| 46 | + echo "Base folder for help ..." |
| 47 | + FOLDER="_base" |
| 48 | + if [ -d "$FOLDER" ] && [ "$(ls -A $FOLDER)" ]; then |
| 49 | + cd "$FOLDER" |
| 50 | + zip -r -9 ../_output/Help-.zip . |
| 51 | + cd .. |
| 52 | + else |
| 53 | + echo "Directory $FOLDER not exists, skipping ..." |
| 54 | + fi |
| 55 | + echo "End : Base folder for help" |
| 56 | + |
| 57 | + SRC_DIR="_invariant" |
| 58 | + mkdir -p $SRC_DIR |
| 59 | + echo "::endgroup::" |
| 60 | + |
| 61 | + for dir in */ ; do |
| 62 | + dir=${dir%/} |
| 63 | + echo "::group::Language: $dir" |
| 64 | +
|
| 65 | + case "$dir" in |
| 66 | + _*) continue ;; |
| 67 | + esac |
| 68 | +
|
| 69 | + echo "Copying language invariant data ..." |
| 70 | + cp -r -T -v "$SRC_DIR"/. "$dir"/ |
| 71 | + cd $dir |
| 72 | + echo "_lang|$dir" >> _config.txt |
| 73 | + echo "::endgroup::" |
| 74 | + [ -f "./fts-keywords.lst" ] && bash ../_ftsbuilder/indexBuild.sh "." |
| 75 | + echo "::group::Language: $dir - zipping directory" |
| 76 | + echo "Zipping ..." |
| 77 | + zip -r -9 ../_output/Help-$dir.zip . |
| 78 | + cd .. |
| 79 | + echo "Language: $dir done." |
| 80 | + echo "::endgroup::" |
| 81 | + done |
| 82 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 83 | + echo "Bundling finished." |
| 84 | +
|
| 85 | + - name: Create tag |
| 86 | + id: newtag |
| 87 | + if: steps.pub.outputs.exists == 'true' |
| 88 | + run: | |
| 89 | + echo "::group::Version overview" |
| 90 | + VERSION=$(awk '/^## /{print $2; exit}' CHANGELOG.md) |
| 91 | + BODY=$(awk '/^## /{if (seen++) exit} seen' CHANGELOG.md | tail -n +2) |
| 92 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 93 | + echo "body<<EOF" >> $GITHUB_OUTPUT |
| 94 | + echo "$BODY" >> $GITHUB_OUTPUT |
| 95 | + echo "EOF" >> $GITHUB_OUTPUT |
| 96 | + echo "::endgroup::" |
| 97 | + |
| 98 | + TAG="$VERSION" |
| 99 | +
|
| 100 | + echo "::group::Old release delete" |
| 101 | + RELEASE_ID=$(curl -s -H "Authorization: token $TOKEN" \ |
| 102 | + https://api.github.com/repos/$REPO/releases/tags/$TAG | jq -r .id) |
| 103 | +
|
| 104 | + if [ "$RELEASE_ID" != "null" ]; then |
| 105 | + echo "Deleting release ID $RELEASE_ID" |
| 106 | + curl -s -X DELETE -H "Authorization: token $TOKEN" \ |
| 107 | + https://api.github.com/repos/$REPO/releases/$RELEASE_ID |
| 108 | + fi |
| 109 | + echo "::endgroup::" |
| 110 | + |
| 111 | + echo "::group::Old tag delete" |
| 112 | + if git ls-remote --tags origin | grep -q "$TAG"; then |
| 113 | + git tag -d "$TAG" || true |
| 114 | + git push origin ":refs/tags/$TAG" || true |
| 115 | + fi |
| 116 | + echo "::endgroup::" |
| 117 | +
|
| 118 | + echo "::group::New tag created" |
| 119 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 120 | + git tag $TAG |
| 121 | + git push origin $TAG || true |
| 122 | + echo "::endgroup::" |
| 123 | + |
| 124 | + - name: Create release |
| 125 | + id: crelease |
| 126 | + if: steps.pub.outputs.exists == 'true' |
| 127 | + uses: actions/create-release@v1 |
| 128 | + with: |
| 129 | + tag_name: ${{ steps.newtag.outputs.tag }} |
| 130 | + release_name: ${{ steps.newtag.outputs.tag }} |
| 131 | + body: ${{ steps.newtag.outputs.body }} |
| 132 | + env: |
| 133 | + GITHUB_TOKEN: ${{ secrets._TOKEN }} |
| 134 | + |
| 135 | + - name: Upload helps for languages |
| 136 | + if: steps.pub.outputs.exists == 'true' |
| 137 | + env: |
| 138 | + GITHUB_TOKEN: ${{ secrets._TOKEN }} |
| 139 | + TAG: ${{ steps.newtag.outputs.tag }} |
| 140 | + REPO: ${{ github.repository }} |
| 141 | + run: | |
| 142 | + cd _output |
| 143 | + |
| 144 | + find . -type f -name "*.zip" -print0 | while IFS= read -r -d '' file; do |
| 145 | + echo "Language bundle to upload: $file" |
| 146 | + unzip "$file" _config.txt |
| 147 | + echo "_version|$TAG" >> _config.txt |
| 148 | + echo "_prjname|$REPO" >> _config.txt |
| 149 | + zip -u -o "$file" _config.txt |
| 150 | + rm _config.txt |
| 151 | + gh release upload "$TAG" "$file" --repo "$REPO" --clobber |
| 152 | + done |
0 commit comments