Chrome Extension Release #3
This file contains 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 Extension Release | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version number for the extension' | |
required: true | |
default: '1.0' | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
# リポジトリをチェックアウト | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# manifest.jsonのversionを手動で指定したversionに更新 | |
- name: Update version in manifest.json | |
id: update_manifest | |
run: | | |
VERSION="${{ github.event.inputs.version }}" # 入力されたバージョン番号 | |
echo "Updating version to $VERSION" | |
jq --arg version "$VERSION" '.version = $version' manifest.json > manifest_updated.json | |
mv manifest_updated.json manifest.json | |
# manifest.jsonの更新をコミット | |
- name: Commit changes | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add manifest.json | |
git commit -m "Update manifest.json version to $VERSION" | |
# manifest.jsonの更新をプッシュ | |
- name: Push changes to repository | |
run: | | |
git push origin HEAD:${{ github.ref }} | |
# 拡張機能をzip化 | |
- name: Create zip package | |
run: | | |
zip -r chrome_extension.zip . -x "*.git*" | |
# Chrome Web Store APIを使ってアップロード | |
- name: Upload to Chrome Web Store | |
env: | |
CLIENT_ID: ${{ secrets.CHROME_WEBSTORE_CLIENT_ID }} | |
CLIENT_SECRET: ${{ secrets.CHROME_WEBSTORE_CLIENT_SECRET }} | |
REFRESH_TOKEN: ${{ secrets.CHROME_WEBSTORE_REFRESH_TOKEN }} | |
EXTENSION_ID: ${{ secrets.EXTENSION_ID }} | |
run: | | |
# Google APIの認証を取得 | |
echo "Fetching access token..." | |
ACCESS_TOKEN=$(curl -s -X POST "https://oauth2.googleapis.com/token" \ | |
-d "client_id=${CLIENT_ID}" \ | |
-d "client_secret=${CLIENT_SECRET}" \ | |
-d "refresh_token=${REFRESH_TOKEN}" \ | |
-d "grant_type=refresh_token" | jq -r '.access_token') | |
# 拡張機能をアップロード | |
echo "Uploading extension..." | |
curl -X POST "https://www.googleapis.com/upload/chromewebstore/v1.1/items/${EXTENSION_ID}/?uploadType=media" \ | |
-H "Authorization: Bearer $ACCESS_TOKEN" \ | |
-F "file=@chrome_extension.zip" | |
# Chrome Web Storeで公開 | |
- name: Publish extension | |
env: | |
CLIENT_ID: ${{ secrets.CHROME_WEBSTORE_CLIENT_ID }} | |
CLIENT_SECRET: ${{ secrets.CHROME_WEBSTORE_CLIENT_SECRET }} | |
REFRESH_TOKEN: ${{ secrets.CHROME_WEBSTORE_REFRESH_TOKEN }} | |
EXTENSION_ID: ${{ secrets.EXTENSION_ID }} | |
run: | | |
# Google APIの認証を取得 | |
ACCESS_TOKEN=$(curl -s -X POST "https://oauth2.googleapis.com/token" \ | |
-d "client_id=${CLIENT_ID}" \ | |
-d "client_secret=${CLIENT_SECRET}" \ | |
-d "refresh_token=${REFRESH_TOKEN}" \ | |
-d "grant_type=refresh_token" | jq -r '.access_token') | |
# Chrome Web Storeで公開 | |
curl -X POST "https://www.googleapis.com/chromewebstore/v1.1/items/${EXTENSION_ID}/publish" \ | |
-H "Authorization: Bearer $ACCESS_TOKEN" |