Publish Extension #138
This file contains 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: "Publish Extension" | |
on: | |
workflow_dispatch: | |
inputs: | |
NEW_CUSTOM_VERSION: | |
description: | | |
(OPTIONAL) >>> LEAVE EMPTY BY DEFAULT <<< It will default to today's date in the format 'y.m.d'. | |
For Major.Minor.Custom version number (NO LEADING ZEROS) e.g. 1.1.1. | |
required: false | |
jobs: | |
generate-version: | |
name: Generate extension version | |
runs-on: ubuntu-latest | |
outputs: | |
ext-version: ${{ steps.retreive-version.outputs.ext-version }} | |
ext-version-num: ${{ steps.retreive-version.outputs.ext-version-num }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get extension version | |
id: retreive-version | |
env: | |
CUSTOM_VERSION: ${{ github.event.inputs.NEW_CUSTOM_VERSION }} | |
run: | | |
if [[ -n "${{ env.CUSTOM_VERSION}}" ]] | |
then | |
# Only match when yy.mm.dd has no leading 0's | |
if [[ "${{ env.CUSTOM_VERSION }}" =~ ^(?<year>[1-9][0-9])\.(?<month>[1-9]|1[0-2])\.(?<day>[1-9]|[1-2][0-9]|3[0-1])$ ]]; then | |
EXT_VERSION=${{ env.CUSTOM_VERSION }} | |
else | |
echo "Invalid NEW_CUSTOM_VERSION format. Leading zeros are not allowed in the year, month, or day." >&2 | |
exit 1 | |
fi | |
else | |
# we use DATE multiple times | |
DATE=$(date) | |
EXT_VERSION=$(date -d "$DATE" +%y.%-m.%-d); | |
while git rev-parse "refs/tags/$EXT_VERSION" >/dev/null 2>&1; do | |
echo "Tag $EXT_VERSION already exists. Incrementing day." | |
DATE=$(date -d "$DATE + 1 day") | |
EXT_VERSION=$(date -d "$DATE" +%y.%-m.%-d); | |
done; | |
fi | |
echo "Setting extension version to $EXT_VERSION" | |
echo "ext-version=$EXT_VERSION" >> $GITHUB_OUTPUT | |
# Remove dots and pad to two digits and remove spaces | |
EXT_VERSION_NUM=$(echo $EXT_VERSION | sed 's/\./ /g' | xargs -n1 | awk '{printf "%02d", $1;}' | xargs) | |
echo "Setting extension version number to $EXT_VERSION_NUM" | |
echo "ext-version-num=$EXT_VERSION_NUM" >> $GITHUB_OUTPUT | |
create-zip: | |
runs-on: ubuntu-latest | |
needs: | |
- generate-version | |
strategy: | |
matrix: | |
node-version: [20.x] | |
env: | |
EXT_VERSION: ${{ needs.generate-version.outputs.ext-version }} | |
steps: | |
- name: Authorized by | |
run: echo "${{ github.event.sender.login }}" | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: '0' | |
- name: Set up Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'npm' | |
- name: Update manifest | |
run: | | |
echo "New Version: ${{ env.EXT_VERSION }}" | |
sed -i'' -e 's|"version":.*|"version": "${{ env.EXT_VERSION }}",|' src/manifest.json | |
cat src/manifest.json | |
- name: Install dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: release-${{ env.EXT_VERSION }} | |
path: ./dist/* | |
- name: Zip it! zip it good! | |
id: create-zip | |
run: | | |
mkdir build | |
zip -r ./build/release-${{ env.EXT_VERSION }}.zip ./dist/* | |
- uses: ncipollo/release-action@v1 | |
with: | |
name: ${{ env.EXT_VERSION }} | |
tag: ${{ env.EXT_VERSION }} | |
artifacts: ./build/release-${{ env.EXT_VERSION }}.zip | |
generateReleaseNotes: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Tag with new version | |
id: create-tag | |
run: | | |
git tag ${{ env.EXT_VERSION }} | |
git push --tags | |
allow-version: | |
name: Add allowed version to server | |
needs: | |
- generate-version | |
- create-zip | |
env: | |
EXT_VERSION_NUM: ${{ needs.generate-version.outputs.ext-version-num }} | |
VERSIONS_FILE: '/var/www/mh-hunt-helper/src/versions.txt' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "${{ secrets.DO_KEY }}" > ~/.ssh/do.key | |
chmod 600 ~/.ssh/do.key | |
cat >>~/.ssh/config <<END | |
Host do | |
HostName ${{ secrets.DO_IP }} | |
User ${{ secrets.DO_USER }} | |
Port ${{ secrets.DO_PORT }} | |
IdentityFile ~/.ssh/do.key | |
StrictHostKeyChecking no | |
END | |
- name: Allow new version if not already | |
run: | | |
echo "Setting version on server to ${{ env.EXT_VERSION_NUM }}" | |
ssh do 'grep -qxF "${{ env.EXT_VERSION_NUM }}" ${{ ENV.VERSIONS_FILE }} || echo "${{ env.EXT_VERSION_NUM }}" >> ${{ ENV.VERSIONS_FILE }}' | |
chrome-submit: | |
name: Submit to Chrome | |
needs: | |
- generate-version | |
- create-zip | |
env: | |
EXT_VERSION: ${{ needs.generate-version.outputs.ext-version }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/download-artifact@v4 | |
name: Get extension artifact | |
with: | |
name: release-${{ env.EXT_VERSION }} | |
path: ./dist | |
- name: Create chrome artifact | |
run: | | |
mkdir build | |
zip -r chrome-extension.zip ./dist/* | |
- name: Upload new release zip to Chrome Webstore | |
uses: Klemensas/chrome-extension-upload-action@1df3cdf4047a4789bc61a64a125994d8caf23572 | |
with: | |
refresh-token: ${{ secrets.CHROME_WEBSTORE_REFRESH_TOKEN }} | |
client-id: ${{ secrets.CHROME_WEBSTORE_CLIENT_ID }} | |
client-secret: ${{ secrets.CHROME_WEBSTORE_CLIENT_SECRET }} | |
file-name: chrome-extension.zip | |
app-id: ${{ secrets.CHROME_WEBSTORE_ADDON_ID }} | |
publish: true | |
firefox-submit: | |
name: Submit to Firefox | |
needs: | |
- generate-version | |
- create-zip | |
env: | |
EXT_VERSION: ${{ needs.generate-version.outputs.ext-version }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/download-artifact@v4 | |
name: Get extension artifact | |
with: | |
name: release-${{ env.EXT_VERSION }} | |
path: ./dist | |
- name: Display structure of downloaded files | |
run: ls -R | |
- name: Upload new release to Firefox Webstore | |
run: npx -y web-ext sign --channel=listed --source-dir=./dist/ --verbose --api-key ${{ secrets.FIREFOX_WEBSTORE_API_KEY }} --api-secret ${{ secrets.FIREFOX_WEBSTORE_API_SECRET }} |