-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shota-kitazawa
committed
May 3, 2024
1 parent
2c1410a
commit 87bcd4c
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: cleanup reviewapps | ||
|
||
on: | ||
schedule: | ||
- cron: '*/30 * * * *' | ||
|
||
# this workflow should not work with cleanup workflow | ||
concurrency: reviewapps | ||
|
||
jobs: | ||
cleanup: | ||
name: create reviewapp files to dreamkast-infra | ||
runs-on: ubuntu-latest | ||
steps: | ||
- 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: Install ecspresso | ||
uses: kayac/ecspresso@v2 | ||
|
||
- name: Cleanup | ||
working-directory: dreamkast-infra/ecspresso/reviewapps | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
PREFIX: weaver- | ||
shell: bash -x {0} | ||
run: | | ||
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 | ||
for exp in $EXPECTED; do | ||
[ "$act" = "$exp" ] && EXIST=true | ||
done | ||
[ $EXIST = true ] && continue | ||
bash -x $act/cleanup.sh | ||
rm -rf $act | ||
done | ||
- name: Commit files | ||
id: commit_files | ||
continue-on-error: true | ||
working-directory: dreamkast-infra/ | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git status | ||
git add -A | ||
git commit -a -F- <<EOM | ||
cleanup ReviewApps by GHA in ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} | ||
EOM | ||
- 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: staging/weaver-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 (staging/weaver-main)", | ||
body: "**this PR is automatically created & merged**", | ||
head: "staging/weaver-main", | ||
base: "main" | ||
}); | ||
await github.rest.pulls.merge({ | ||
owner: "cloudnativedaysjp", | ||
repo: "dreamkast-infra", | ||
pull_number: pr.data.number, | ||
merge_method: "squash", | ||
}); |