diff --git a/.github/workflows/reviewapp-cleanup.yml b/.github/workflows/reviewapp-cleanup.yml new file mode 100644 index 0000000..11e12df --- /dev/null +++ b/.github/workflows/reviewapp-cleanup.yml @@ -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 "action@github.com" + git config --local user.name "GitHub Action" + git status + git add -A + git commit -a -F- <