diff --git a/.github/workflows/publish-extension.yaml b/.github/workflows/publish-extension.yaml index aaf02d838..c1d1bd76d 100644 --- a/.github/workflows/publish-extension.yaml +++ b/.github/workflows/publish-extension.yaml @@ -24,7 +24,7 @@ on: workflow_dispatch: inputs: version: - description: Set any override version number to use (overrides on-master and tag-pattern). If it matches ^[0-9.]+, it will set the appVersion and will be visible to users. Non-matching values will cause appVersion to be used. + description: Set any override version number to use (overrides on-master and tag-pattern). If it matches ^v?[0-9.]+, it will set the appVersion (v will be removed) and will be visible to users. Non-matching values will cause appVersion to be used. required: true default: 'dev' target: @@ -44,17 +44,8 @@ jobs: TAG_VERSION: ${{ github.event.release.tag_name }} EVENT_NAME: ${{ github.event_name }} run: | - # Use the override value by preference - VERSION=${INPUT_VERSION} - # If no valid override input was entered, then try to use the release tag - if [[ ! $VERSION =~ ^[0-9.]+ ]]; then - VERSION=${TAG_VERSION} - fi - # If Version matches a release pattern, then set the appVersion in the files to be published - if [[ $VERSION =~ ^[0-9.]+ ]]; then - sed -i -E "s/appVersion\s*=\s*[^;]+/appVersion = '$VERSION'/" ./service-worker.js - sed -i -E "s/params..appVersion[^=]+?=\s*[^;]+/params['appVersion'] = '$VERSION'/" ./www/js/app.js - fi + chmod +x ./scripts/rewrite_app_version_number.sh + ./scripts/rewrite_app_version_number.sh # Publish to docker only if explicitly requested or we are releasing - name: Build and push to docker if: github.event.inputs.target == 'docker' || github.event_name == 'release' @@ -64,7 +55,7 @@ jobs: credentials: | DOCKERIO_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} DOCKERIO_TOKEN=${{ secrets.DOCKERHUB_PASSWORD }} - tag-pattern: /^[0-9]([0-9.]+).*$/ + tag-pattern: /^v?([0-9.]+)$/ latest-on-tag: true dockerfile: docker/dockerfile-moz-extension.pwa restrict-to: kiwix/kiwix-js @@ -75,6 +66,7 @@ jobs: if: github.event.inputs.target == 'ghpages' || github.event_name == 'release' || github.event_name == 'push' run: | # Set up username and email + echo "Publishing to GitHub pages..." git config user.name "GitHub Actions Bot" git config user.email "<>" if [ ! -z "$(git status --porcelain)" ]; then diff --git a/scripts/rewrite_app_version_number.sh b/scripts/rewrite_app_version_number.sh new file mode 100644 index 000000000..a71585ee7 --- /dev/null +++ b/scripts/rewrite_app_version_number.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# [Script run by publish-extension workflow] +# Replaces the version numbers in app.js and service-worker.js with the following priority: +# +# 1. use the override value set in the workflow dispatch; +# 2. use the tag pattern (if no override value was set) +# +# This script can be tested manually by replacing ${INPUT_VERSION} and ${TAG_VERSION} +# with test strings + +# Use the override value by preference +VERSION=${INPUT_VERSION} +if [[ $VERSION =~ ^v?[0-9.]+ ]]; then + VERSION=$(sed 's/^v//' <<<"$VERSION") # Remove any leading v + echo "Using the valid override input and setting version to $VERSION" +else + # If no valid override input was entered, then try to use the release tag + VERSION=${TAG_VERSION} + if [[ $VERSION =~ ^v?[0-9.]+ ]]; then + VERSION=$(sed 's/^v//' <<<"$VERSION") + echo "Using the release tag and setting version to $VERSION" + else + echo "No valid override or tag was provided. File version numbers were unchanged." + echo "To rewrite version numbers in app, ensure the tag matches ^v?[0-9.]+" + fi +fi +# If Version matches a release pattern, then set the appVersion in the files to be published +if [[ $VERSION =~ ^[0-9.]+ ]]; then + echo "Rewriting appVersion in service-worker.js and app.js to $VERSION ..." + sed -i -E "s/appVersion\s*=\s*[^;]+/appVersion = '$VERSION'/" ./service-worker.js + sed -i -E "s/params..appVersion[^=]+?=\s*[^;]+/params['appVersion'] = '$VERSION'/" ./www/js/app.js +fi