Skip to content

Instantly share code, notes, and snippets.

@syossan27
Last active December 17, 2021 12:13
Show Gist options
  • Save syossan27/0b77df9062ce1157e3cfa8bd8513b5b2 to your computer and use it in GitHub Desktop.
Save syossan27/0b77df9062ce1157e3cfa8bd8513b5b2 to your computer and use it in GitHub Desktop.
# PRに対して特定のコメントが作成されたら使用中に更新&デプロイタグをpush
# dev1へアプリ1をデプロイする部分のみ記述(本来はdev2, dev3も記述)
name: Deploy by Pull Request Comment
on:
issue_comment:
types:
- created
jobs:
deploy_by_pr_comment:
# 発生したイベント元がPR、かつ「deploy dev_1」というコメントであればジョブを実行(dev_2,3の処理は割愛)
if: github.event.issue.pull_request != null && github.event.comment.body == 'deploy dev_1'
runs-on: ubuntu-latest
steps:
- name: Google Cloud SDKのセットアップ
uses: google-github-actions/[email protected]
with:
# セットアップに必要なSecretsは事前にリポジトリ毎に設定しておく
# 参考URL: https://cloud.google.com/blog/ja/products/serverless/deploying-serverless-platforms-github-actions
project_id: ${{ secrets.PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true # 後の処理で認証が通るようにtrue
- name: PRに紐づくブランチを取得
uses: actions/github-script@v4
id: target-branch
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
const pull_request = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
return pull_request.data.head.ref
- name: ブランチ名をもとにチェックアウト
uses: actions/checkout@v2
with:
ref: ${{ steps.target-branch.outputs.result }}
- name: dev1のデプロイタグをpushしてデプロイ
run: |
git tag dev_deploy_1 -f
git push origin dev_deploy_1 -f
- name: 使用中へ切り替え
run: |
# PRのURLを書き込んだ遷移先テキストファイルの作成
touch 1.txt
echo ${{ github.event.issue.html_url }} > 1.txt
# 遷移先テキストファイルをアプリ1のディレクトリに配置
gsutil -h "Cache-Control: no-store" -m cp -r ./1.txt gs://example-bucket/app-1/
# 使用状況画像を使用中画像へ置換
gsutil -h "Cache-Control: no-store" -m cp -r gs://example-bucket/green.png gs://example-bucket/app-1/1.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment