Chrome Store Publish #54
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: Chrome Store Publish | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_run: | |
| workflows: | |
| - Version Management | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Existing release tag to publish (for example: v1.55.0)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: chrome-store-publish-${{ github.event_name }}-${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.event_name == 'push' && github.ref_name || github.event.workflow_run.id }} | |
| cancel-in-progress: false | |
| jobs: | |
| publish-to-chrome-store: | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event_name != 'workflow_run' || | |
| (github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.head_branch == 'main') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve release tag | |
| id: release_meta | |
| run: | | |
| skip_publish='false' | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| release_tag="${{ github.event.inputs.tag }}" | |
| git fetch --tags --force | |
| if ! git rev-parse --verify --quiet "refs/tags/${release_tag}" >/dev/null; then | |
| echo "Tag ${release_tag} not found." | |
| exit 1 | |
| fi | |
| release_sha="$(git rev-list -n 1 "refs/tags/${release_tag}")" | |
| git checkout --detach "${release_sha}" | |
| elif [ "${{ github.event_name }}" = "workflow_run" ]; then | |
| trigger_sha="${{ github.event.workflow_run.head_sha }}" | |
| git fetch origin main --tags --force | |
| # Version Management creates the release commit/tag after trigger_sha. | |
| release_sha="$( | |
| git log "${trigger_sha}..origin/main" --format='%H%x09%s' \ | |
| | grep -E $'\tchore\\(release\\): bump version to v[0-9]+\\.[0-9]+\\.[0-9]+ \\[no-cli\\]$' \ | |
| | head -n 1 \ | |
| | cut -f1 || true | |
| )" | |
| if [ -z "${release_sha}" ]; then | |
| echo "No release bump commit found after workflow head SHA ${trigger_sha}; skipping publish." | |
| skip_publish='true' | |
| else | |
| release_tag="$(git tag --points-at "${release_sha}" | grep '^v' | head -n 1 || true)" | |
| if [ -z "${release_tag}" ]; then | |
| echo "No v* tag points at detected release commit ${release_sha}; skipping publish." | |
| skip_publish='true' | |
| else | |
| git checkout --detach "${release_sha}" | |
| fi | |
| fi | |
| else | |
| release_tag="${GITHUB_REF_NAME}" | |
| release_sha="${GITHUB_SHA}" | |
| fi | |
| echo "tag=${release_tag}" >> "$GITHUB_OUTPUT" | |
| echo "sha=${release_sha}" >> "$GITHUB_OUTPUT" | |
| echo "skip=${skip_publish}" >> "$GITHUB_OUTPUT" | |
| - name: Skip notice | |
| if: steps.release_meta.outputs.skip == 'true' | |
| run: echo "No new release tag detected for this workflow_run event." | |
| - name: Ensure tag commit is on main | |
| if: steps.release_meta.outputs.skip != 'true' | |
| run: | | |
| git fetch origin main --depth=1 | |
| if ! git merge-base --is-ancestor "${{ steps.release_meta.outputs.sha }}" "origin/main"; then | |
| echo "Tag ${{ steps.release_meta.outputs.tag }} is not on main branch commit history." | |
| exit 1 | |
| fi | |
| - name: Build extension package | |
| if: steps.release_meta.outputs.skip != 'true' | |
| run: ./.github/scripts/build-extension.sh dist "nenya-${{ steps.release_meta.outputs.tag }}.zip" | |
| - name: Authenticate Google service account | |
| if: steps.release_meta.outputs.skip != 'true' | |
| id: google_auth | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: '${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}' | |
| token_format: access_token | |
| access_token_scopes: https://www.googleapis.com/auth/chromewebstore | |
| - name: Publish to Chrome Web Store | |
| if: steps.release_meta.outputs.skip != 'true' | |
| env: | |
| CWS_EXTENSION_ID: ${{ secrets.CWS_EXTENSION_ID }} | |
| CWS_ACCESS_TOKEN: ${{ steps.google_auth.outputs.access_token }} | |
| CWS_PUBLISH_TARGET: ${{ secrets.CWS_PUBLISH_TARGET }} | |
| CWS_PUBLISHER_ID: ${{ secrets.CWS_PUBLISHER_ID }} | |
| run: ./.github/scripts/publish-to-cws.sh "dist/nenya-${{ steps.release_meta.outputs.tag }}.zip" |