-
Notifications
You must be signed in to change notification settings - Fork 799
87 lines (76 loc) · 3.21 KB
/
pr-is-up-to-date.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: PR is up-to-date
on:
pull_request_target:
branches: [ trunk ]
push:
branches: [ trunk ]
tags:
- pr-update-to
- pr-update-to-projects/**
jobs:
check:
name: Check
runs-on: ubuntu-latest
timeout-minutes: 5 # 2021-03-23: The run on push to the tag might take a minute or two.
steps:
# We basically have two workflows in one here, one for pushes to trunk and one for PRs and pushes to tags.
# The reason we don't separate them into two is because GitHub's UI would then always be showing a skipped job
# in the PR check list, which is kind of annoying.
# First, the "PR or tag" job.
- name: Checkout trunk for tag push or PR
uses: actions/checkout@v4
if: github.event_name != 'push' || github.ref != 'refs/heads/trunk'
with:
ref: trunk
token: ${{ secrets.API_TOKEN_GITHUB }}
# On a PR, we need to fetch (but not check out) the actual PR too.
- name: Deepen to merge base
if: github.event_name != 'push'
uses: ./.github/actions/deepen-to-merge-base
with:
checkout: false
- name: Determine tags for PR or tag and paths for tag push
id: determine
if: github.event_name != 'push' || github.ref != 'refs/heads/trunk'
env:
REF: ${{ github.event.pull_request.head.sha }}
run: |
TAGS=()
TAG=
PATHS=
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
TAG="${GITHUB_REF#refs/tags/}"
if [[ "$TAG" == pr-update-to-* ]]; then
PATHS="${TAG#pr-update-to-}"
fi
else
TMP="$(git -c core.quotepath=off diff --name-only "origin/trunk...${REF}" projects/*/*/ | sed -nE 's!^(projects/[^/]+/[^/]+)/.*!pr-update-to-\1!p' | sort -u)"
mapfile -t TAGS <<<"$TMP"
TAGS+=( pr-update-to )
fi
echo "pr-tags=${TAGS[*]}" >> "$GITHUB_OUTPUT"
echo "push-tag=$TAG" >> "$GITHUB_OUTPUT"
echo "push-paths=$PATHS" >> "$GITHUB_OUTPUT"
- name: Check PR or tag push
if: github.event_name != 'push' || github.ref != 'refs/heads/trunk'
uses: ./projects/github-actions/pr-is-up-to-date
with:
tags: ${{ steps.determine.outputs.pr-tags }}
tag: ${{ steps.determine.outputs.push-tag }}
paths: ${{ steps.determine.outputs.push-paths }}
token: ${{ secrets.API_TOKEN_GITHUB }}
status: PR is up to date
# Second, the "push to trunk" job.
- name: Checkout push to trunk
uses: actions/checkout@v4
if: github.event_name == 'push' && github.ref == 'refs/heads/trunk'
with:
# The "Check whether the tag needs updating for trunk commit" needs the previous commit for diffing.
fetch-depth: 2
token: ${{ secrets.API_TOKEN_GITHUB }}
- name: Wait for prior instances of the workflow to finish
if: github.event_name == 'push' && github.ref == 'refs/heads/trunk'
uses: ./.github/actions/turnstile
- name: Check whether the tag needs updating for trunk commit
if: github.event_name == 'push' && github.ref == 'refs/heads/trunk'
run: .github/files/pr-update-to.sh