Skip to content

Commit 00ec795

Browse files
authored
[6.x] Reusable GitHub workflows (#14743)
1 parent 3e78b6f commit 00ec795

4 files changed

Lines changed: 7 additions & 150 deletions

File tree

.github/workflows/pr-title.yml

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,6 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14-
pr-title: # zizmor: ignore[anonymous-definition]
15-
runs-on: ubuntu-latest
14+
pr-title:
15+
uses: statamic/.github/.github/workflows/pr-title.yml@bebe92309b4276e45ebc0d0c65854fb2ecf786ba
1616
permissions: {}
17-
steps:
18-
- name: Validate PR title matches target branch
19-
env:
20-
PR_TITLE: ${{ github.event.pull_request.title }}
21-
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
22-
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
23-
run: |
24-
# Validates PR title against target branch
25-
# Returns error message if invalid, empty string if valid
26-
validate_pr_title() {
27-
local target_branch="$1"
28-
local pr_title="$2"
29-
local default_branch="$3"
30-
31-
# Check if target branch is a version branch (e.g., 5.x, 4.x)
32-
if [[ $target_branch =~ ^([0-9]+)\.x$ ]]; then
33-
local version="${BASH_REMATCH[1]}"
34-
if [[ ! $pr_title =~ ^\[$version\.x\][[:space:]] ]]; then
35-
echo "PR targeting '$target_branch' must have title starting with '[$version.x] '"
36-
return
37-
fi
38-
39-
# Check if target branch is master (next major version)
40-
elif [[ $target_branch == "master" ]]; then
41-
local current_version="${default_branch//\.x/}"
42-
local next_version=$((current_version + 1))
43-
if [[ ! $pr_title =~ ^\[$next_version\.x\][[:space:]] ]]; then
44-
echo "PR targeting 'master' must have title starting with '[$next_version.x] '"
45-
return
46-
fi
47-
48-
# For other branches, just enforce that there's a version prefix
49-
else
50-
if [[ ! $pr_title =~ ^\[[0-9]+\.x\][[:space:]] ]]; then
51-
echo "PR title must start with a version prefix like '[5.x] '"
52-
return
53-
fi
54-
fi
55-
56-
echo ""
57-
}
58-
59-
echo "PR Title: $PR_TITLE"
60-
echo "Base Branch: $BASE_BRANCH"
61-
echo "Default Branch: $DEFAULT_BRANCH"
62-
63-
ERROR=$(validate_pr_title "$BASE_BRANCH" "$PR_TITLE" "$DEFAULT_BRANCH")
64-
65-
if [[ -n $ERROR ]]; then
66-
echo $ERROR
67-
exit 1
68-
fi
69-
70-
echo "PR title validation passed"
Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Pull Requests
22

3-
# Credit: https://github.com/github/docs/blob/main/.github/workflows/notify-when-maintainers-cannot-edit.yaml
4-
# https://github.com/laravel/.github/blob/main/.github/workflows/pull-requests.yml
5-
63
on:
74
pull_request_target: # zizmor: ignore[dangerous-triggers]
85
types:
@@ -15,66 +12,7 @@ concurrency:
1512
cancel-in-progress: true
1613

1714
jobs:
18-
uneditable: # zizmor: ignore[anonymous-definition]
19-
runs-on: ubuntu-latest
15+
uneditable:
16+
uses: statamic/.github/.github/workflows/pull-requests.yml@bebe92309b4276e45ebc0d0c65854fb2ecf786ba
2017
permissions:
2118
pull-requests: write # post comment and close PRs that don't allow maintainer edits
22-
steps:
23-
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
24-
with:
25-
script: |
26-
const repo = context.repo.repo;
27-
28-
const query = `
29-
query($number: Int!) {
30-
repository(owner: "statamic", name: "${repo}") {
31-
pullRequest(number: $number) {
32-
headRepositoryOwner {
33-
login
34-
}
35-
maintainerCanModify
36-
state
37-
}
38-
}
39-
}
40-
`;
41-
42-
const pullNumber = context.issue.number;
43-
const variables = { number: pullNumber };
44-
45-
try {
46-
console.log(`Check for maintainer edit access ...`);
47-
const result = await github.graphql(query, variables);
48-
console.log(JSON.stringify(result, null, 2));
49-
const pullRequest = result.repository.pullRequest;
50-
51-
if (pullRequest.headRepositoryOwner.login === 'statamic') {
52-
console.log('PR owned by statamic');
53-
return;
54-
}
55-
56-
if (pullRequest.state !== 'OPEN') {
57-
console.log('PR has already been closed or merged');
58-
return;
59-
}
60-
61-
if (!pullRequest.maintainerCanModify) {
62-
console.log('PR not owned by statamic and does not have maintainer edits enabled');
63-
64-
await github.rest.issues.createComment({
65-
issue_number: pullNumber,
66-
owner: 'statamic',
67-
repo,
68-
body: "Thanks for submitting a PR!\n\nIn order to review and merge PRs most efficiently, we require that all PRs grant maintainer edit access before we review them. For information on how to do this, [see the relevant GitHub documentation](https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork). Additionally, GitHub doesn't allow maintainer permissions from organization accounts. Please resubmit this PR from a personal GitHub account with maintainer permissions enabled."
69-
});
70-
71-
await github.rest.pulls.update({
72-
pull_number: pullNumber,
73-
owner: 'statamic',
74-
repo,
75-
state: 'closed'
76-
});
77-
}
78-
} catch(e) {
79-
console.log(e);
80-
}

.github/workflows/stale.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,7 @@ on: # zizmor: ignore[concurrency-limits]
77
permissions: {}
88

99
jobs:
10-
stale: # zizmor: ignore[anonymous-definition]
11-
runs-on: ubuntu-latest
10+
stale:
11+
uses: statamic/.github/.github/workflows/stale.yml@bebe92309b4276e45ebc0d0c65854fb2ecf786ba
1212
permissions:
1313
issues: write # mark issues stale and close them
14-
pull-requests: write # mark pull requests stale and close them
15-
steps:
16-
- uses: actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f # v10.2.0
17-
with:
18-
repo-token: ${{ secrets.GITHUB_TOKEN }}
19-
days-before-stale: 60
20-
days-before-close: 7
21-
ascending: true
22-
only-labels: 'needs more info'
23-
stale-issue-label: stale
24-
stale-issue-message: >
25-
This issue has not had recent activity and has been marked as stale — by me, a robot.
26-
Simply reply to keep it open and send me away. If you do nothing, I will close it in
27-
a week. I have no feelings, so whatever you do is fine by me.

.github/workflows/zizmor.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,5 @@ concurrency:
1919

2020
jobs:
2121
zizmor:
22-
name: zizmor
23-
runs-on: ubuntu-latest
22+
uses: statamic/.github/.github/workflows/zizmor.yml@7e941c239074d66da6cad3322bec3b1005c80cf7
2423
permissions: {}
25-
steps:
26-
- name: Checkout repository
27-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28-
with:
29-
persist-credentials: false
30-
31-
- name: Run zizmor
32-
uses: zizmorcore/zizmor-action@5f14fd08f7cf1cb1609c1e344975f152c7ee938d # v0.5.6
33-
with:
34-
advanced-security: false
35-
annotations: true
36-
persona: pedantic

0 commit comments

Comments
 (0)