From c55c7e1522b24023a975accb89a5fda38680d366 Mon Sep 17 00:00:00 2001 From: modos189 Date: Fri, 29 Jul 2022 12:09:09 +0300 Subject: [PATCH] Removing the PR build from the site after a PR merge --- .github/workflows/merge_pr.yml | 42 +++++++++++++++++++++++++++++++++ .github/workflows/upload_pr.yml | 13 ++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/merge_pr.yml diff --git a/.github/workflows/merge_pr.yml b/.github/workflows/merge_pr.yml new file mode 100644 index 000000000..0f0d19a44 --- /dev/null +++ b/.github/workflows/merge_pr.yml @@ -0,0 +1,42 @@ +name: After PR merging + +on: + pull_request: + types: + - closed + +jobs: + if_merged: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v3 + env: + WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} + with: + repository: ${{ secrets.WEBSITE_REPO }} + ref: 'master' + token: ${{ secrets.API_TOKEN_GITHUB }} + + - name: Setup git config + env: + WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} + run: | + git config user.name "userz" + git config user.email "<>" + + - name: Delete old build artifacts + env: + WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} + run: | + git rm -r static/build/artifact/PR${{ github.event.number }}/ + git commit -m "🤖 PR №${{ github.event.number }} merged, deleting old build artifacts" + + - run: git push origin master + env: + WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} diff --git a/.github/workflows/upload_pr.yml b/.github/workflows/upload_pr.yml index 4d70894a8..3fdee3531 100644 --- a/.github/workflows/upload_pr.yml +++ b/.github/workflows/upload_pr.yml @@ -17,6 +17,9 @@ jobs: steps: - name: 'Download artifact' uses: actions/github-script@v6 + env: + WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} with: script: | let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ @@ -37,9 +40,15 @@ jobs: fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build.zip`, Buffer.from(download.data)); - name: 'Unzip artifact' + env: + WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} run: unzip build.zip - name: Set env + env: + WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} run: | echo "PR_NUMBER=$(cat ./.metadata/number)" >> "$GITHUB_ENV" echo "COMMIT_HASH=$(cat ./.metadata/commit)" >> "$GITHUB_ENV" @@ -60,12 +69,12 @@ jobs: destination_folder: 'static/build/artifact/PR${{ env.PR_NUMBER }}/' user_email: 'example@email.com' user_name: 'IITC Updates' - commit_message: '🤖 New IITC test build from https://github.com/${{ github.repository }}/commit/${{ github.sha }}' + commit_message: '🤖 New build PR №${{ env.PR_NUMBER }} from https://github.com/${{ github.repository }}/commit/${{ github.sha }}' - name: Comment with build url - if: ${{ env.WEBSITE_REPO != '' }} env: WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} uses: marocchino/sticky-pull-request-comment@v2 with: header: pr_release