From 4188cc8964a57dcb1a0ad02c58368f6314b567b9 Mon Sep 17 00:00:00 2001 From: Philip Colmer Date: Mon, 13 May 2024 18:40:40 +0100 Subject: [PATCH] Add pull request support --- .github/workflows/close_pr.yml | 22 ++++++++++++++++++++ .github/workflows/pull_request.yml | 32 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/workflows/close_pr.yml create mode 100644 .github/workflows/pull_request.yml diff --git a/.github/workflows/close_pr.yml b/.github/workflows/close_pr.yml new file mode 100644 index 0000000..a243783 --- /dev/null +++ b/.github/workflows/close_pr.yml @@ -0,0 +1,22 @@ +name: ClosePullRequestAction + +on: + pull_request_target: + types: [closed] + branches: [ main ] + +jobs: + close: + runs-on: self-hosted + steps: + - name: close pull request + run: | + PR_NUMBER=$(jq -r ".pull_request.number" $GITHUB_EVENT_PATH) + echo "Cleaning up after $PR_NUMBER has closed" + BUILDDIR="/srv/websitepreview/$AWS_STATIC_SITE_URL-$PR_NUMBER" + if [ -d "$BUILDDIR" ]; then + echo "Removing website review directory" + rm -rf "$BUILDDIR" + else + echo "No website review directory ($BUILDDIR) to remove" + fi diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..96be5f8 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,32 @@ +name: PullRequestAction + +on: + pull_request_target: + branches: [ main ] + +# Cancel in-progress jobs or runs for the current pull request +concurrency: + group: ${{ github.workflow }}-${{ github.event.number }} + cancel-in-progress: true + +jobs: + process-pull-request: + runs-on: self-hosted + steps: + - name: Fetch git repository + uses: actions/checkout@v4.1.1 + with: + fetch-depth: "0" + + - name: Initialise status + run: /srv/github-action-scripts/init-deploy-preview.sh + env: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Merge test branch + uses: linaro-its/merge-test-branch@v2.7 + + - name: Build site + run: /srv/github-action-scripts/build-astro-site.sh + env: + TOKEN: ${{ secrets.GITHUB_TOKEN }}