Skip to content

Commit 832e237

Browse files
committed
refactor to run on push
1 parent e3dac1c commit 832e237

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

.github/workflows/pr-deploy.yaml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# 3. when a PR is updated
55
name: Deploy PR
66
on:
7-
pull_request:
8-
types: synchronize
7+
push:
98
workflow_dispatch:
109
inputs:
1110
pr_number:
@@ -37,12 +36,30 @@ permissions:
3736
pull-requests: write
3837

3938
concurrency:
40-
group: ${{ github.workflow }}-PR-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
39+
group: ${{ github.workflow }}-${{ github.ref }}
4140
cancel-in-progress: true
4241

4342
jobs:
43+
check_pr:
44+
runs-on: ubuntu-latest
45+
outputs:
46+
PR_OPEN: ${{ steps.check_pr.outputs.pr_open }}
47+
steps:
48+
- name: Check if PR is open
49+
id: check_pr
50+
run: |
51+
set -euo pipefail
52+
if [[ $(gh pr view --json state | jq -r '.state') != "OPEN" ]]; then
53+
echo "a PR is not open. skipping"
54+
pr_open=$(gh pr view --json state | jq -r '.state' != "OPEN")
55+
fi
56+
echo "pr_open=$pr_open" >> $GITHUB_OUTPUT
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
4460
get_info:
45-
if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request'
61+
needs: check_pr
62+
if: ${{ needs.check_pr.outputs.PR_OPEN == 'true' }}
4663
outputs:
4764
PR_NUMBER: ${{ steps.pr_info.outputs.PR_NUMBER }}
4865
PR_TITLE: ${{ steps.pr_info.outputs.PR_TITLE }}
@@ -59,13 +76,16 @@ jobs:
5976
id: pr_info
6077
run: |
6178
set -euo pipefail
62-
PR_NUMBER=${{ github.event.inputs.pr_number || github.event.pull_request.number }}
63-
PR_TITLE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/coder/coder/pulls/$PR_NUMBER | jq -r '.title')
64-
PR_BRANCH=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/coder/coder/pulls/$PR_NUMBER | jq -r '.head.ref')
65-
echo "PR_URL=https://github.com/coder/coder/pull/$PR_NUMBER" >> $GITHUB_OUTPUT
79+
PR_NUMBER=$(gh pr view --json number | jq -r '.number')
80+
PR_TITLE=$(gh pr view --json title | jq -r '.title')
81+
PR_URL=$(gh pr view --json url | jq -r '.url')
82+
echo "PR_URL=$PR_URL" >> $GITHUB_OUTPUT
6683
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
6784
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_OUTPUT
6885
echo "PR_BRANCH=$PR_BRANCH" >> $GITHUB_OUTPUT
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
PR_BRANCH: ${{ github.ref }}
6989

7090
- name: Set required tags
7191
id: set_tags
@@ -134,6 +154,7 @@ jobs:
134154
uses: dorny/paths-filter@v2
135155
id: filter
136156
with:
157+
base: ${{ steps.pr_info.outputs.PR_BRANCH }}
137158
filters: |
138159
all:
139160
- "**"

0 commit comments

Comments
 (0)