Publish extension #34
This file contains hidden or 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: | |
| environment: | |
| description: 'Environment' | |
| type: choice | |
| options: | |
| - development | |
| - production | |
| default: production | |
| permissions: | |
| # for updating tag/release | |
| contents: write | |
| jobs: | |
| main: | |
| name: Build and create tag | |
| runs-on: ubuntu-latest | |
| environment: ${{ github.event.inputs.environment }} | |
| outputs: | |
| version: ${{ steps.config.outputs.version }} | |
| tag_name: ${{ steps.config.outputs.tag_name }} | |
| ext_path_zip: ${{ steps.config.outputs.ext_path_zip }} | |
| ext_path_xpi: ${{ steps.config.outputs.ext_path_xpi }} | |
| artifact_dir: ${{ steps.config.outputs.artifact_dir }} | |
| artifact_zip: ${{ steps.config.outputs.artifact_zip }} | |
| artifact_xpi: ${{ steps.config.outputs.artifact_xpi }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Configure and verify | |
| id: config | |
| env: | |
| TIMEZONE: ${{ vars.TIMEZONE || 'UTC' }} | |
| run: | | |
| VERSION=$(jq -r '.version' './src/manifest.chromium.json') | |
| for file in src/manifest*.json; do | |
| VERSION2=$(jq -r '.version' "$file") | |
| if [ "$VERSION" != "$VERSION2" ]; then | |
| echo "❌ Mismatching manifest version: '$file'" | |
| exit 1 | |
| fi | |
| done | |
| if [ '${{ github.event.inputs.environment }}' = 'production' ]; then | |
| EXPECTED_LINE="## [$VERSION] - $(TZ="$TIMEZONE" date +%Y-%m-%d)" | |
| if ! grep -Fxq "$EXPECTED_LINE" CHANGELOG.md; then | |
| echo "❌ Missing expected changelog line: $EXPECTED_LINE" | |
| exit 1 | |
| fi | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag_name=$VERSION" >> $GITHUB_OUTPUT | |
| echo "ext_path_zip=dist/webscrapbook.zip" >> $GITHUB_OUTPUT | |
| echo "ext_path_zip2=dist/webscrapbook2.zip" >> $GITHUB_OUTPUT | |
| echo "ext_path_xpi=dist/webscrapbook.xpi" >> $GITHUB_OUTPUT | |
| echo "artifact_dir=dist" >> $GITHUB_OUTPUT | |
| echo "artifact_zip=webscrapbook-zip" >> $GITHUB_OUTPUT | |
| echo "artifact_zip2=webscrapbook-zip2" >> $GITHUB_OUTPUT | |
| echo "artifact_xpi=webscrapbook-xpi" >> $GITHUB_OUTPUT | |
| - name: Set extension name suffix | |
| if: vars.EXTENSION_NAME_SUFFIX != '' | |
| run: | | |
| for file in src/_locales/*/messages.json; do | |
| echo "Updating '$file'..." | |
| jq '.ExtensionName.message += "${{ vars.EXTENSION_NAME_SUFFIX }}"' "$file" > .tmp.json | |
| mv .tmp.json "$file" | |
| done | |
| - name: Set Firefox extension ID | |
| if: vars.FIREFOX_EXTENSION_ID != '' | |
| run: | | |
| for file in src/manifest.firefox*.json; do | |
| echo "Updating '$file'..." | |
| jq '.browser_specific_settings.gecko.id = "${{ vars.FIREFOX_EXTENSION_ID }}"' "$file" > .tmp.json | |
| mv .tmp.json "$file" | |
| done | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Verify no code issue | |
| run: npm run lint | |
| - name: Build MV2 extension for Edge | |
| run: | | |
| npm run pack:chromium2 | |
| mv ${{ steps.config.outputs.ext_path_zip }} ${{ steps.config.outputs.ext_path_zip2 }} | |
| - name: Build extension | |
| run: npm run pack | |
| - name: Create Git tag | |
| if: github.event.inputs.environment == 'production' | |
| run: | | |
| git tag --force ${{ steps.config.outputs.tag_name }} | |
| git push origin ${{ steps.config.outputs.tag_name }} | |
| - name: Upload artifact (ZIP) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.config.outputs.artifact_zip }} | |
| path: ${{ steps.config.outputs.ext_path_zip }} | |
| - name: Upload artifact (ZIP2) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.config.outputs.artifact_zip2 }} | |
| path: ${{ steps.config.outputs.ext_path_zip2 }} | |
| - name: Upload artifact (XPI) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.config.outputs.artifact_xpi }} | |
| path: ${{ steps.config.outputs.ext_path_xpi }} | |
| upload_cws: | |
| name: Upload to Chrome Web Store | |
| runs-on: ubuntu-latest | |
| needs: main | |
| environment: ${{ github.event.inputs.environment }} | |
| steps: | |
| - name: Download artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ needs.main.outputs.artifact_zip }} | |
| path: ${{ needs.main.outputs.artifact_dir }} | |
| - name: Upload to Chrome Web Store | |
| uses: mnao305/[email protected] | |
| with: | |
| file-path: ${{ needs.main.outputs.ext_path_zip }} | |
| extension-id: ${{ vars.CHROME_EXTENSION_ID }} | |
| # https://github.com/fregante/chrome-webstore-upload-keys | |
| client-id: ${{ secrets.CHROME_CLIENT_ID }} | |
| client-secret: ${{ secrets.CHROME_CLIENT_SECRET }} | |
| refresh-token: ${{ secrets.CHROME_REFRESH_TOKEN }} | |
| upload_edge: | |
| name: Upload to Microsoft Edge Add-ons | |
| runs-on: ubuntu-latest | |
| needs: main | |
| environment: ${{ github.event.inputs.environment }} | |
| steps: | |
| - name: Download artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ needs.main.outputs.artifact_zip2 }} | |
| path: ${{ needs.main.outputs.artifact_dir }} | |
| - name: Upload to Microsoft Edge Add-ons | |
| uses: wdzeng/edge-addon@v2 | |
| with: | |
| zip-path: ${{ needs.main.outputs.ext_path_zip2 }} | |
| product-id: ${{ vars.EDGE_PRODUCT_ID }} | |
| client-id: ${{ secrets.EDGE_CLIENT_ID }} | |
| api-key: ${{ secrets.EDGE_API_KEY }} | |
| upload_firefox: | |
| name: Upload to Firefox Add-ons | |
| runs-on: ubuntu-latest | |
| needs: main | |
| environment: ${{ github.event.inputs.environment }} | |
| steps: | |
| - name: Download artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ needs.main.outputs.artifact_xpi }} | |
| path: ${{ needs.main.outputs.artifact_dir }} | |
| - name: Upload to Firefox Add-ons | |
| uses: kewisch/action-web-ext@v1 | |
| with: | |
| cmd: sign | |
| # 'listed' or 'unlisted' | |
| channel: ${{ vars.FIREFOX_EXTENSION_CHANNEL }} | |
| source: ${{ needs.main.outputs.ext_path_xpi }} | |
| artifacts: dist | |
| apiKey: ${{ secrets.FIREFOX_API_KEY }} | |
| apiSecret: ${{ secrets.FIREFOX_API_SECRET }} |