From 5c130c4fdae517dabe1b198d22bb9440467a561b Mon Sep 17 00:00:00 2001 From: ShotaKitazawa Date: Tue, 17 Sep 2024 23:59:53 +0900 Subject: [PATCH] update actions --- .github/workflows/gitops-prd.yml | 85 +++++++++++++++++++++++++ .github/workflows/gitops-stg.yml | 75 +--------------------- .github/workflows/reviewapp-cleanup.yml | 17 +++-- .github/workflows/reviewapp.yml | 6 +- 4 files changed, 102 insertions(+), 81 deletions(-) diff --git a/.github/workflows/gitops-prd.yml b/.github/workflows/gitops-prd.yml index b9f0d851..6815b229 100644 --- a/.github/workflows/gitops-prd.yml +++ b/.github/workflows/gitops-prd.yml @@ -78,3 +78,88 @@ jobs: pull_number: pr.data.number, merge_method: "squash", }); + + gitops-ecs: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v5 + + - name: Install jsonnet + run: | + go install github.com/google/go-jsonnet/cmd/jsonnet@latest + go install github.com/google/go-jsonnet/cmd/jsonnetfmt@latest + + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.PRIVATE_KEY }} + + - name: Checkout dreamkast-infra + uses: actions/checkout@v4 + with: + repository: cloudnativedaysjp/dreamkast-infra + path: dreamkast-infra + token: ${{ steps.generate_token.outputs.token }} + + - name: get tag name + id: get-tag-name + run: echo tag-name="${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT + + - name: Update image-tags + working-directory: dreamkast-infra/ecspresso/prod + run: | + cat << _EOL_ | jsonnet - > ./const.libsonnet.tmp + local const = import './const.libsonnet'; + + const + { + imageTags: const.imageTags + { + dreamkast_ui: "${{ steps.get-tag-name.outputs.tag-name }}", + }, + } + _EOL_ + mv const.libsonnet.tmp const.libsonnet + jsonnetfmt -i const.libsonnet + + - name: Commit files + id: commit_files + continue-on-error: true + working-directory: dreamkast-infra/ + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git status + git add -A + git commit -am "Bump docker tag (${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${{ steps.get-tag-name.outputs.tag-name }})" + + - name: Push changes + if: steps.commit_files.outcome == 'success' + uses: ad-m/github-push-action@master + with: + github_token: ${{ steps.generate_token.outputs.token }} + repository: cloudnativedaysjp/dreamkast-infra + directory: dreamkast-infra + branch: gitops/production/ui-main + + - name: Create and Merge Pull Request + if: steps.commit_files.outcome == 'success' + uses: "actions/github-script@v7" + with: + github-token: ${{ steps.generate_token.outputs.token }} + script: | + const pr = await github.rest.pulls.create({ + owner: "cloudnativedaysjp", + repo: "dreamkast-infra", + title: "Automated PR (gitops/production/ui-main)", + body: "**this PR is automatically created & merged**", + head: "gitops/production/ui-main", + base: "main" + }); + await github.rest.pulls.merge({ + owner: "cloudnativedaysjp", + repo: "dreamkast-infra", + pull_number: pr.data.number, + merge_method: "squash", + }); diff --git a/.github/workflows/gitops-stg.yml b/.github/workflows/gitops-stg.yml index 3cc65d7b..a21440e2 100644 --- a/.github/workflows/gitops-stg.yml +++ b/.github/workflows/gitops-stg.yml @@ -6,80 +6,7 @@ on: - main jobs: - gitops: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Generate token - id: generate_token - uses: tibdex/github-app-token@v1 - with: - app_id: ${{ secrets.APP_ID }} - private_key: ${{ secrets.PRIVATE_KEY }} - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Checkout dreamkast-infra - uses: actions/checkout@v3 - with: - repository: cloudnativedaysjp/dreamkast-infra - path: dreamkast-infra - token: ${{ steps.generate_token.outputs.token }} - - - name: Update Kubernetes resources - working-directory: dreamkast-infra/manifests/app/dreamkast/overlays/staging/main - run: | - kustomize edit set image dreamkast-ui=${{ steps.login-ecr.outputs.registry }}/dreamkast-ui:${{ github.sha }} - - - name: Commit files - working-directory: dreamkast-infra/ - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git status - git add -A - git commit -am "Bump docker tag (${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA})" - - - name: Push changes - uses: ad-m/github-push-action@master - with: - github_token: ${{ steps.generate_token.outputs.token }} - repository: cloudnativedaysjp/dreamkast-infra - directory: dreamkast-infra - branch: staging/ui-main - - - name: Create and Merge Pull Request - uses: "actions/github-script@v6" - with: - github-token: ${{ steps.generate_token.outputs.token }} - script: | - const pr = await github.rest.pulls.create({ - owner: "cloudnativedaysjp", - repo: "dreamkast-infra", - title: "Automated PR (staging/ui-main)", - body: "**this PR is automatically created & merged**", - head: "staging/ui-main", - base: "main" - }); - await github.rest.pulls.merge({ - owner: "cloudnativedaysjp", - repo: "dreamkast-infra", - pull_number: pr.data.number, - merge_method: "squash", - }); - - ecs: + gitops-ecs: runs-on: ubuntu-latest steps: - name: Install Go diff --git a/.github/workflows/reviewapp-cleanup.yml b/.github/workflows/reviewapp-cleanup.yml index d68877a9..b5145f77 100644 --- a/.github/workflows/reviewapp-cleanup.yml +++ b/.github/workflows/reviewapp-cleanup.yml @@ -41,10 +41,12 @@ jobs: env: GH_TOKEN: ${{ github.token }} PREFIX: ui- - shell: bash -x {0} + shell: bash -xe {0} run: | + set -e EXPECTED="$(gh pr list --repo ${{ github.repository }} --label 'reviewapps' --json number --jq '.[].number' | sed 's/^\(.*\)$/'$PREFIX'\1/g')" ACTUAL="$(ls | grep -E ^$PREFIX)" + # If present only in ACTUAL, cleanup for act in $ACTUAL; do EXIST=false @@ -55,6 +57,7 @@ jobs: bash -x $act/cleanup.sh rm -rf $act done + - name: Commit files id: commit_files continue-on-error: true @@ -67,6 +70,12 @@ jobs: git commit -a -F- <> $GITHUB_ENV + - name: Push changes if: steps.commit_files.outcome == 'success' uses: ad-m/github-push-action@master @@ -74,7 +83,7 @@ jobs: github_token: ${{ steps.generate_token.outputs.token }} repository: cloudnativedaysjp/dreamkast-infra directory: dreamkast-infra - branch: staging/ui-main + branch: gitops/development/ui-main_${{ env.UNIXTIME }} - name: Create and Merge Pull Request if: steps.commit_files.outcome == 'success' @@ -85,9 +94,9 @@ jobs: const pr = await github.rest.pulls.create({ owner: "cloudnativedaysjp", repo: "dreamkast-infra", - title: "Automated PR (staging/ui-main)", + title: "Automated PR (gitops/development/ui-main)", body: "**this PR is automatically created & merged**", - head: "staging/ui-main", + head: "gitops/development/ui-main_${{ env.UNIXTIME }}", base: "main" }); await github.rest.pulls.merge({ diff --git a/.github/workflows/reviewapp.yml b/.github/workflows/reviewapp.yml index a38e0e05..0c46db47 100644 --- a/.github/workflows/reviewapp.yml +++ b/.github/workflows/reviewapp.yml @@ -99,7 +99,7 @@ jobs: github_token: ${{ steps.generate_token.outputs.token }} repository: cloudnativedaysjp/dreamkast-infra directory: dreamkast-infra - branch: staging/ui-main + branch: gitops/development/ui-main - name: Create and Merge Pull Request if: steps.commit_files.outcome == 'success' @@ -110,9 +110,9 @@ jobs: const pr = await github.rest.pulls.create({ owner: "cloudnativedaysjp", repo: "dreamkast-infra", - title: "Automated PR (staging/ui-main)", + title: "Automated PR (gitops/development/ui-main)", body: "**this PR is automatically created & merged**", - head: "staging/ui-main", + head: "gitops/development/ui-main", base: "main" }); await github.rest.pulls.merge({