Skip to content

Commit

Permalink
Removing the PR build from the site after a PR merge
Browse files Browse the repository at this point in the history
  • Loading branch information
modos189 committed Jul 29, 2022
1 parent dd25877 commit 3ddea05
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/merge_pr.yml
Original file line number Diff line number Diff line change
@@ -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 != '' }}
13 changes: 11 additions & 2 deletions .github/workflows/upload_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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"
Expand All @@ -60,12 +69,12 @@ jobs:
destination_folder: 'static/build/artifact/PR${{ env.PR_NUMBER }}/'
user_email: '[email protected]'
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
Expand Down

0 comments on commit 3ddea05

Please sign in to comment.