repository link update : base - added steganography filter for puiHeader #1383
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publishing | |
| on: | |
| push: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| inputs: | |
| source_branch: | |
| description: 'Source branch' | |
| required: true | |
| default: 'master' | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_branch || github.ref }} | |
| submodules: recursive | |
| - name: Check if should be published | |
| if: ${{ github.event_name != 'workflow_dispatch' && !contains(github.event.head_commit.message, '[pub]') }} | |
| run: | | |
| echo "[pub] string is missing in commit message, skipping ..." | |
| exit 0 | |
| - name: Publish | |
| id: pub | |
| if: ${{ github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '[pub]') }} | |
| run: | | |
| mkdir -p hvdata/data | |
| echo "::group::Processing deps.lst" | |
| if [ -f deps.lst ]; then | |
| dependList=$(cat deps.lst) | |
| for line in $(printf '%s\n' "$dependList"); do | |
| cleanedText=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
| [ -z "$cleanedText" ] && continue | |
| num_pipes=$(echo "$cleanedText" | awk -F'|' '{print NF-1}') | |
| set -- $(echo "$cleanedText" | awk -F'|' '{printf "%s %s %s", $1, $2, $3}') | |
| if [ "$num_pipes" -eq 1 ]; then | |
| out="hvdata/data/$1" | |
| url="$2" | |
| elif [ "$num_pipes" -eq 2 ]; then | |
| out="hvdata/$1" | |
| url="$2" | |
| else | |
| continue | |
| fi | |
| echo "Downloading from -> to : $url -> $out" | |
| wget -q -O "$out" "$url" | |
| done | |
| else | |
| echo "deps.lst file not defined, skipping ..." | |
| fi | |
| echo "Processing of deps.lst finished" | |
| echo "::endgroup::" | |
| echo "::group::Processing zip subdirectory" | |
| rm -rf ./zip/prism/README.md ./zip/prism/.git | |
| rm -rf ./zip/i/README.md ./zip/i/.git ./zip/i/CHANGELOG.md ./zip/i/.github | |
| rm ./zip/base/README.md ./zip/base/LICENSE | |
| shopt -s nullglob | |
| find ./zip/lang -maxdepth 1 -type f -exec rm -f {} + | |
| find ./zip/lang -mindepth 1 -maxdepth 1 -type d -printf "%f\n" > ./zip/lang/__dir.lst | |
| find ./zip/styles -mindepth 1 -maxdepth 1 -type f -name "*.css" -printf "%f\n" > ./zip/styles/__dir.lst | |
| cp -rf ./zip/* ./hvdata/data | |
| shopt -u nullglob | |
| echo "::endgroup::" | |
| echo "::group::Get version" | |
| __VERSION=$(awk '/^## /{print $2; exit}' CHANGELOG.md) | |
| echo $__VERSION | |
| echo "::endgroup::" | |
| echo "::group::Add tag to zip as version info" | |
| echo "_version|$__VERSION" >> ./hvdata/data/_config.txt | |
| echo "_prjname|HelpViewer/HelpViewer" >> ./hvdata/data/_config.txt | |
| echo "::endgroup::" | |
| rm -rf ./jsconfig.json | |
| echo "::group::Pre packaging cleanup" | |
| find . -type f -name ".git" -print -exec rm -rf {} + 2>/dev/null || true | |
| find . -type d -name ".extras" -print -exec rm -rf {} + 2>/dev/null || true | |
| echo "::endgroup::" | |
| echo "::group::Packaging" | |
| cd hvdata/data | |
| zip -r -9 ../data.zip . | |
| cd .. | |
| rm -rf data/ | |
| rm ./README.md ./LICENSE | |
| echo "::endgroup::" | |
| echo "::group::Set DEBUG_MODE to false" | |
| sed -i "s|^const DEBUG_MODE.*|const DEBUG_MODE = false;|" ../index.html | |
| sed -i "s|^const DATA_FILE_PATH_BASE.*|const DATA_FILE_PATH_BASE = 'hvdata/data';|" ./appmain.js | |
| echo "::endgroup::" | |
| echo "::group::Packaging deploy bundle" | |
| cd .. | |
| mkdir _distrib | |
| cd _distrib | |
| find .. -maxdepth 1 -type f \ | |
| ! -name 'Dockerfile' \ | |
| ! -name 'deps.lst' \ | |
| ! -name '*.md' \ | |
| ! -name '.*' \ | |
| -exec cp {} . \; | |
| cp -rf ../hvdata . | |
| rm -rf ./.git | |
| echo "<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title><meta name="robots" content="noindex,nofollow"></head><body></body></html>" > ./hvdata/index.html | |
| zip -r -9 ../package.zip . | |
| echo "::endgroup::" | |
| echo "::group::sw.js cache list update" | |
| mapfile -t bundleFileList < <(zipinfo -1 ../package.zip | grep -v '^sw\.js$' | grep -v '/$') | |
| alteredNames=() | |
| for s in "${bundleFileList[@]}"; do | |
| s="/${s#./}" | |
| alteredNames+=("'$s'") | |
| done | |
| joined=$(IFS=, ; echo "${alteredNames[*]}") | |
| newR="const CACHE_FILES = [ ${joined} ];" | |
| echo "Newly planned cache list: ${newR}" | |
| sed -i "2s|.*|$newR|" ./sw.js | |
| sed -i "1s/^const CACHE_NAME = 'helpviewer-cache-.*';/const CACHE_NAME = 'helpviewer-cache-$(date +%Y%m%d)';/" ./sw.js | |
| echo "::endgroup::" | |
| echo "::group::sw.js new bundling" | |
| zip -d ../package.zip sw.js | |
| zip ../package.zip sw.js | |
| echo "::endgroup::" | |
| echo "::group::Bundling finishing" | |
| cd .. | |
| if [ -f ./package.zip ]; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| echo "::endgroup::" | |
| - name: Create tag | |
| id: newtag | |
| if: steps.pub.outputs.exists == 'true' | |
| run: | | |
| echo "::group::Version overview" | |
| VERSION=$(awk '/^## /{print $2; exit}' CHANGELOG.md) | |
| BODY=$(awk '/^## /{if (seen++) exit} seen' CHANGELOG.md | tail -n +2) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "body<<EOF" >> $GITHUB_OUTPUT | |
| echo "$BODY" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| echo "::endgroup::" | |
| TAG="$VERSION" | |
| #echo "::group::Old release delete" | |
| #RELEASE_ID=$(curl -s -H "Authorization: token $TOKEN" \ | |
| # https://api.github.com/repos/$REPO/releases/tags/$TAG | jq -r .id) | |
| #if [ "$RELEASE_ID" != "null" ]; then | |
| # echo "Deleting release ID $RELEASE_ID" | |
| # curl -s -X DELETE -H "Authorization: token $TOKEN" \ | |
| # https://api.github.com/repos/$REPO/releases/$RELEASE_ID | |
| #fi | |
| #echo "::endgroup::" | |
| # | |
| #echo "::group::Old tag delete" | |
| #if git ls-remote --tags origin | grep -q "$TAG"; then | |
| # git tag -d "$TAG" || true | |
| # git push origin ":refs/tags/$TAG" || true | |
| #fi | |
| #echo "::endgroup::" | |
| echo "::group::New tag created" | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| git tag $TAG | |
| git push origin $TAG || true | |
| echo "::endgroup::" | |
| - name: Create release | |
| id: crelease | |
| if: steps.pub.outputs.exists == 'true' | |
| uses: actions/create-release@v1 | |
| with: | |
| tag_name: ${{ steps.newtag.outputs.version }} | |
| release_name: ${{ steps.newtag.outputs.version }} | |
| body: ${{ steps.newtag.outputs.body }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets._TOKEN }} | |
| - name: Download all zip assets from HelpViewer/helpUser and add it to bundle | |
| if: steps.pub.outputs.exists == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| #release_name="${{ steps.newtag.outputs.version }}" | |
| #api_url="https://api.github.com/repos/HelpViewer/helpUser/releases/tags/$release_name" | |
| api_url="https://api.github.com/repos/HelpViewer/helpUser/releases/latest" | |
| release=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$api_url") | |
| mkdir -p hlp | |
| echo "$release" | jq -c '.assets[] | select(.name | endswith(".zip"))' | while read asset; do | |
| name=$(echo "$asset" | jq -r '.name') | |
| url=$(echo "$asset" | jq -r '.url') | |
| echo "Downloading $name..." | |
| curl -L -H "Accept: application/octet-stream" \ | |
| -H "Authorization: token $GITHUB_TOKEN" \ | |
| "$url" -o "hlp/$name" | |
| done | |
| echo "::endgroup::" | |
| echo "::group::Bundling user guide help file" | |
| zip -r ./package.zip hlp | |
| echo "::endgroup::" | |
| - name: Upload asset | |
| if: steps.pub.outputs.exists == 'true' | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets._TOKEN }} | |
| with: | |
| upload_url: ${{ steps.crelease.outputs.upload_url }} | |
| asset_path: ./package.zip | |
| asset_name: package.zip | |
| asset_content_type: application/zip | |
| - name: Set up Docker Buildx | |
| if: steps.pub.outputs.exists == 'true' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| if: steps.pub.outputs.exists == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Normalize repository owner | |
| if: steps.pub.outputs.exists == 'true' | |
| id: normalize | |
| run: | | |
| echo "owner_lc=${GITHUB_REPOSITORY_OWNER,,}" >> "$GITHUB_OUTPUT" | |
| - name: Build and push Docker image | |
| if: steps.pub.outputs.exists == 'true' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64 | |
| tags: | | |
| ghcr.io/${{ steps.normalize.outputs.owner_lc }}/helpviewer:latest | |
| ghcr.io/${{ steps.normalize.outputs.owner_lc }}/helpviewer:${{ steps.newtag.outputs.version }} | |
| build-args: | | |
| PACKAGE_TAG=${{ steps.newtag.outputs.version }} |