Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in publish extension workflow and add logging #829

Merged
merged 5 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions .github/workflows/publish-extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions scripts/rewrite_app_version_number.sh
Original file line number Diff line number Diff line change
@@ -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