feat: 구글 애널리틱스 태그 추가 #26
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: Build and Release Extension | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.meta.outputs.version }} | |
| asset_name: ${{ steps.meta.outputs.asset_name }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Read version metadata | |
| id: meta | |
| run: | | |
| VERSION=$(node -e "console.log(JSON.parse(require('fs').readFileSync('manifest.json', 'utf8')).version)") | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "asset_name=eHelper-v${VERSION}.zip" >> "$GITHUB_OUTPUT" | |
| - name: Verify version sync | |
| run: npm run version:check | |
| - name: Verify tag matches version | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: npm run version:check -- --tag "${GITHUB_REF_NAME}" | |
| - name: Install deps | |
| run: npm ci | |
| - name: Typecheck | |
| run: npm run typecheck | |
| - name: Build | |
| run: npm run build | |
| - name: Archive dist | |
| run: cd dist && zip -r "../${{ steps.meta.outputs.asset_name }}" . | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: extension-zip | |
| path: ${{ steps.meta.outputs.asset_name }} | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Verify version sync | |
| run: npm run version:check -- --tag "${GITHUB_REF_NAME}" | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: extension-zip | |
| path: release-assets | |
| - name: Generate release notes | |
| run: node scripts/generate-release-notes.mjs --version "${{ needs.build.outputs.version }}" > release-notes.md | |
| - name: Create or update GitHub release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| TAG_NAME: ${{ github.ref_name }} | |
| ASSET_NAME: ${{ needs.build.outputs.asset_name }} | |
| run: | | |
| ASSET_PATH="release-assets/${ASSET_NAME}" | |
| TITLE="eHelper ${TAG_NAME}" | |
| if gh release view "${TAG_NAME}" >/dev/null 2>&1; then | |
| gh release upload "${TAG_NAME}" "${ASSET_PATH}" --clobber | |
| gh release edit "${TAG_NAME}" --title "${TITLE}" --notes-file release-notes.md | |
| else | |
| gh release create "${TAG_NAME}" "${ASSET_PATH}" --title "${TITLE}" --notes-file release-notes.md | |
| fi | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| # 승인 전까지 배포 비활성화: | |
| # repo variable `CWS_PUBLISH_ENABLED`를 true로 바꾸기 전에는 실행되지 않음. | |
| if: startsWith(github.ref, 'refs/tags/v') && vars.CWS_PUBLISH_ENABLED == 'true' | |
| steps: | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: extension-zip | |
| path: . | |
| - name: Install jq | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| - name: Get OAuth access token | |
| id: token | |
| run: | | |
| ACCESS_TOKEN=$(curl -s https://oauth2.googleapis.com/token \ | |
| -d client_id="${{ secrets.CHROME_CLIENT_ID }}" \ | |
| -d client_secret="${{ secrets.CHROME_CLIENT_SECRET }}" \ | |
| -d refresh_token="${{ secrets.CHROME_REFRESH_TOKEN }}" \ | |
| -d grant_type=refresh_token | jq -r '.access_token') | |
| if [ -z "$ACCESS_TOKEN" ] || [ "$ACCESS_TOKEN" = "null" ]; then | |
| echo "Failed to get access token" | |
| exit 1 | |
| fi | |
| echo "access_token=$ACCESS_TOKEN" >> "$GITHUB_OUTPUT" | |
| - name: Upload to Chrome Web Store | |
| env: | |
| ASSET_NAME: ${{ needs.build.outputs.asset_name }} | |
| run: | | |
| curl -s -X PUT \ | |
| -H "Authorization: Bearer ${{ steps.token.outputs.access_token }}" \ | |
| -H "x-goog-api-version: 2" \ | |
| -H "Content-Type: application/zip" \ | |
| --data-binary "@${ASSET_NAME}" \ | |
| "https://www.googleapis.com/upload/chromewebstore/v1.1/items/${{ secrets.CHROME_EXTENSION_ID }}" | |
| - name: Publish to Chrome Web Store | |
| run: | | |
| curl -s -X POST \ | |
| -H "Authorization: Bearer ${{ steps.token.outputs.access_token }}" \ | |
| -H "x-goog-api-version: 2" \ | |
| "https://www.googleapis.com/chromewebstore/v1.1/items/${{ secrets.CHROME_EXTENSION_ID }}/publish?publishTarget=default" |