Skip to content

Commit

Permalink
Added GitHub Action to automatically publish the extension
Browse files Browse the repository at this point in the history
  • Loading branch information
modos189 committed Jun 24, 2024
1 parent c26efe8 commit 581761a
Show file tree
Hide file tree
Showing 4 changed files with 1,244 additions and 5 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/chrome-token.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "fetch-chrome-webstore-access-token"

on:
schedule:
- cron: '0 3 2 * *' # At 03:00 on day-of-month 2

jobs:
fetchToken:
runs-on: ubuntu-latest
env:
CHROME_CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }}
if: ${{ env.CHROME_CLIENT_ID }}

steps:
- uses: cardinalby/google-api-fetch-token-action@v1
with:
clientId: ${{ secrets.CHROME_CLIENT_ID }}
clientSecret: ${{ secrets.CHROME_CLIENT_SECRET }}
refreshToken: ${{ secrets.CHROME_REFRESH_TOKEN }}
136 changes: 136 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Publish to stores

on:
workflow_run:
workflows: ["Build IITC Button"]
types: [completed]
workflow_dispatch:

jobs:
check-secret:
runs-on: ubuntu-latest
outputs:
secrets: ${{ steps.key-check.outputs.defined }}
steps:
- name: Check for Secret availability
id: key-check
shell: bash
run: |
if [ "${{ secrets.CHROME_CLIENT_ID }}" != '' ]; then
echo "defined=true" >> $GITHUB_OUTPUT;
else
echo "defined=false" >> $GITHUB_OUTPUT;
fi
build:
name: Publish to stores
runs-on: ubuntu-latest
needs: [check-secret]
if: needs.check-secret.outputs.secrets == 'true'

steps:
- uses: actions/checkout@v4
- name: Zip sources
run: |
zip -r sources.zip . -x ".git/*" ".github/*"
- name: Get artifact ID and name from API
id: get-artifact-id
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const runId = ${{ github.event.workflow_run.id }};
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
const chromeArtifact = artifacts.data.artifacts.find(artifact => artifact.name.includes("chrome"));
if (chromeArtifact) {
core.exportVariable("chromeArtifactId", chromeArtifact.id);
core.exportVariable("chromeArtifactName", chromeArtifact.name);
} else {
core.setFailed("No artifact found with 'chrome' in its name");
}
const firefoxArtifact = artifacts.data.artifacts.find(artifact => artifact.name.includes("firefox"));
if (firefoxArtifact) {
core.exportVariable("firefoxArtifactId", firefoxArtifact.id);
core.exportVariable("firefoxArtifactName", firefoxArtifact.name);
} else {
core.setFailed("No artifact found with 'firefox' in its name");
}
- name: Download Chrome artifact
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: ${{ env.chromeArtifactId }},
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build-chrome.zip`, Buffer.from(download.data));
- name: Download Firefox artifact
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: ${{ env.firefoxArtifactId }},
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build-firefox.zip`, Buffer.from(download.data));
- name: Unpacking and extracting the build type from the artifact
run: |
unzip -d build-chrome build-chrome.zip
unzip -d build-firefox build-firefox.zip
if [ -f "./build-firefox/.metadata/build_type" ]; then
BUILD_TYPE=$(cat ./build-firefox/.metadata/build_type)
echo "BUILD_TYPE=$BUILD_TYPE" >> $GITHUB_ENV
fi
- name: Setting the extension ID and defining the file name
if: ${{ contains(fromJSON('["release", "beta"]'), env.BUILD_TYPE) }}
run: |
if [ "$BUILD_TYPE" == "release" ]; then
echo "CHROME_EXTENSION_ID=${{ vars.CHROME_EXTENSION_ID_RELEASE }}" >> $GITHUB_ENV
echo "FIREFOX_EXTENSION_ID=${{ vars.FIREFOX_EXTENSION_ID_RELEASE }}" >> $GITHUB_ENV
elif [ "$BUILD_TYPE" == "beta" ]; then
echo "CHROME_EXTENSION_ID=${{ vars.CHROME_EXTENSION_ID_BETA }}" >> $GITHUB_ENV
echo "FIREFOX_EXTENSION_ID=${{ vars.FIREFOX_EXTENSION_ID_BETA }}" >> $GITHUB_ENV
fi
echo "CHROME_ZIP=./build-chrome/${{ env.chromeArtifactName }}.zip" >> $GITHUB_ENV
echo "FIREFOX_ZIP=./build-firefox/${{ env.firefoxArtifactName }}.zip" >> $GITHUB_ENV
- uses: actions/setup-node@v4
if: ${{ contains(fromJSON('["release", "beta"]'), env.BUILD_TYPE) }}
with:
node-version: 20
cache: 'npm'

- name: Install dependencies
if: ${{ contains(fromJSON('["release", "beta"]'), env.BUILD_TYPE) }}
run: npm ci

- name: Upload & release
if: ${{ contains(fromJSON('["release", "beta"]'), env.BUILD_TYPE) }}
env:
CHROME_CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }}
CHROME_CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }}
CHROME_REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }}
FIREFOX_JWT_ISSUER: ${{ secrets.FIREFOX_JWT_ISSUER }}
FIREFOX_JWT_SECRET: ${{ secrets.FIREFOX_JWT_SECRET }}
FIREFOX_SOURCES_ZIP: "sources.zip"
run: |
npx publish-extension
Loading

0 comments on commit 581761a

Please sign in to comment.