Subject API の OpenAPI スキーマを追加 (#10) #20
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: CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| environment_name: | |
| description: Environment | |
| required: true | |
| type: choice | |
| options: | |
| - dev | |
| - stg | |
| - qa | |
| - prod | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.inputs.environment_name }} | |
| cancel-in-progress: true | |
| jobs: | |
| set-env: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| environment: ${{ steps.set-env.outputs.environment }} | |
| service_name: ${{ steps.set-env.outputs.service_name }} | |
| image_tag: ${{ steps.set-env.outputs.image_tag }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set Environmet | |
| id: set-env | |
| run: | | |
| # Environment | |
| IS_WORKFLOW_DISPATCH="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment_name != '' }}" | |
| IS_PUSH_TO_MAIN="${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.base_ref == 'main') }}" | |
| if [ $IS_WORKFLOW_DISPATCH = "true" ]; then | |
| export TARGET_ENVIRONMENT="${{ github.event.inputs.environment_name }}" | |
| elif [ $IS_PUSH_TO_MAIN = "true" ]; then | |
| export TARGET_ENVIRONMENT="stg" | |
| else | |
| exit 1 | |
| fi | |
| echo "Environment: $TARGET_ENVIRONMENT" | |
| # Service name suffix | |
| if [ "$TARGET_ENVIRONMENT" = "prod" ]; then | |
| export SERVICE_NAME_SUFFIX="" | |
| else | |
| export SERVICE_NAME_SUFFIX="-$TARGET_ENVIRONMENT" | |
| fi | |
| export REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}') | |
| export SERVICE_NAME=$REPO_NAME$SERVICE_NAME_SUFFIX | |
| export IMAGE_TAG=${{ vars._AR_HOSTNAME }}/${{ vars.PROJECT_ID }}/github-actions/$REPO_NAME/$SERVICE_NAME:${{ github.sha }} | |
| echo "Repository name: $REPO_NAME" | |
| echo "Service name: $SERVICE_NAME" | |
| echo "Image tag: $IMAGE_TAG" | |
| echo "environment=$TARGET_ENVIRONMENT" >> "$GITHUB_OUTPUT" | |
| echo "service_name=$SERVICE_NAME" >> "$GITHUB_OUTPUT" | |
| echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT" | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| env: | |
| SERVICE_NAME: ${{ needs.set-env.outputs.service_name }} | |
| IMAGE_TAG: ${{ needs.set-env.outputs.image_tag }} | |
| needs: | |
| - set-env | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Build | |
| run: | | |
| docker build \ | |
| -t ${{ env.IMAGE_TAG }} \ | |
| . \ | |
| -f Dockerfile \ | |
| --no-cache | |
| - name: Authenticate | |
| id: auth | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }} | |
| service_account: ${{ vars.SERVICE_ACCOUNT }} | |
| - name: Setup Google Cloud | |
| uses: google-github-actions/setup-gcloud@v2 | |
| with: | |
| project_id: ${{ vars.PROJECT_ID }} | |
| - name: Configure Docker | |
| run: | | |
| gcloud auth \ | |
| configure-docker \ | |
| ${{ vars._AR_HOSTNAME }} | |
| - name: Push | |
| run: | | |
| docker push \ | |
| ${{ env.IMAGE_TAG }} | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| environment: ${{ needs.set-env.outputs.environment }} | |
| env: | |
| SERVICE_NAME: ${{ needs.set-env.outputs.service_name }} | |
| IMAGE_TAG: ${{ needs.set-env.outputs.image_tag }} | |
| needs: | |
| - set-env | |
| - build-and-push | |
| steps: | |
| - name: Authenticate | |
| id: auth | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }} | |
| service_account: ${{ vars.SERVICE_ACCOUNT }} | |
| - name: Deploy | |
| id: deploy | |
| uses: google-github-actions/deploy-cloudrun@v2 | |
| with: | |
| service: ${{ env.SERVICE_NAME }} | |
| image: ${{ env.IMAGE_TAG }} | |
| region: ${{ vars._DEPLOY_REGION }} | |
| env_vars: | | |
| ANNOUNCEMENT_API_URL=${{ vars.ANNOUNCEMENT_API_URL }} | |
| env_vars_update_strategy: overwrite | |
| secrets_update_strategy: overwrite |