Skip to content

Publish to stores

Publish to stores #3

Workflow file for this run

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