Skip to content

Commit 99515b4

Browse files
committed
Resolve shared action refs without default-branch writes
1 parent b65777e commit 99515b4

12 files changed

Lines changed: 521 additions & 162 deletions

.github/workflows/auto-assign.yml

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,57 @@ permissions:
2121
pull-requests: write
2222
repository-projects: write
2323

24+
env:
25+
FAST_FORWARD_ACTIONS_REPOSITORY: php-fast-forward/.github
26+
FAST_FORWARD_ACTIONS_REF: ${{ github.repository != 'php-fast-forward/.github' && vars.FAST_FORWARD_ACTIONS_REF || '' }}
27+
2428
jobs:
2529
resolve-project:
2630
runs-on: ubuntu-latest
2731
outputs:
2832
project_number: ${{ steps.resolve.outputs.project-number }}
2933
steps:
34+
- &resolve_shared_action_ref
35+
name: Resolve shared action ref
36+
id: shared_actions
37+
shell: bash
38+
env:
39+
GH_TOKEN: ${{ github.token }}
40+
CURRENT_REF: ${{ github.head_ref || github.ref_name }}
41+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
42+
run: |
43+
set -euo pipefail
44+
45+
if [ -n "${FAST_FORWARD_ACTIONS_REF}" ]; then
46+
ref="${FAST_FORWARD_ACTIONS_REF}"
47+
elif [ "${GITHUB_REPOSITORY}" = "${FAST_FORWARD_ACTIONS_REPOSITORY}" ]; then
48+
if [ "${GITHUB_EVENT_NAME}" = "pull_request_target" ] && [ -n "${BASE_SHA:-}" ]; then
49+
ref="${BASE_SHA}"
50+
else
51+
ref="${CURRENT_REF:-main}"
52+
fi
53+
else
54+
ref="$(gh api "repos/${FAST_FORWARD_ACTIONS_REPOSITORY}/releases/latest" --jq .tag_name 2>/dev/null || true)"
55+
56+
if [ -z "${ref}" ] || [ "${ref}" = "null" ]; then
57+
ref="main"
58+
fi
59+
fi
60+
61+
echo "ref=${ref}" >> "${GITHUB_OUTPUT}"
62+
63+
- &checkout_shared_action_source
64+
name: Checkout shared action source
65+
uses: actions/checkout@v6
66+
with:
67+
repository: ${{ env.FAST_FORWARD_ACTIONS_REPOSITORY }}
68+
ref: ${{ steps.shared_actions.outputs.ref }}
69+
path: .fast-forward-actions
70+
sparse-checkout: |
71+
.github/actions
72+
3073
- id: resolve
31-
uses: php-fast-forward/.github/.github/actions/project-board/resolve@task/2-extract-shared-workflows
74+
uses: ./.fast-forward-actions/.github/actions/project-board/resolve
3275
with:
3376
project: ${{ inputs.project || vars.PROJECT || '' }}
3477

@@ -46,7 +89,10 @@ jobs:
4689
if: github.event_name == 'issues' && needs.resolve-project.outputs.project_number != ''
4790
runs-on: ubuntu-latest
4891
steps:
49-
- uses: php-fast-forward/.github/.github/actions/project-board/sync-status@task/2-extract-shared-workflows
92+
- *resolve_shared_action_ref
93+
- *checkout_shared_action_source
94+
95+
- uses: ./.fast-forward-actions/.github/actions/project-board/sync-status
5096
with:
5197
organization: ${{ github.repository_owner }}
5298
project: ${{ needs.resolve-project.outputs.project_number }}
@@ -58,7 +104,10 @@ jobs:
58104
if: github.event_name == 'pull_request_target' && needs.resolve-project.outputs.project_number != ''
59105
runs-on: ubuntu-latest
60106
steps:
61-
- uses: php-fast-forward/.github/.github/actions/project-board/sync-linked-pr-metadata@task/2-extract-shared-workflows
107+
- *resolve_shared_action_ref
108+
- *checkout_shared_action_source
109+
110+
- uses: ./.fast-forward-actions/.github/actions/project-board/sync-linked-pr-metadata
62111

63112
sync-pull-request-status:
64113
needs: resolve-project
@@ -69,18 +118,21 @@ jobs:
69118
linked_issue_status: ${{ steps.compute.outputs.linked-issue-status }}
70119
pull_request_status: ${{ steps.compute.outputs.pull-request-status }}
71120
steps:
121+
- *resolve_shared_action_ref
122+
- *checkout_shared_action_source
123+
72124
- id: compute
73-
uses: php-fast-forward/.github/.github/actions/project-board/resolve-pr-status@task/2-extract-shared-workflows
125+
uses: ./.fast-forward-actions/.github/actions/project-board/resolve-pr-status
74126

75-
- uses: php-fast-forward/.github/.github/actions/project-board/sync-status@task/2-extract-shared-workflows
127+
- uses: ./.fast-forward-actions/.github/actions/project-board/sync-status
76128
with:
77129
organization: ${{ github.repository_owner }}
78130
project: ${{ needs.resolve-project.outputs.project_number }}
79131
resource-node-id: ${{ github.event.pull_request.node_id }}
80132
status-value: ${{ steps.compute.outputs.pull-request-status }}
81133

82134
- if: steps.compute.outputs.linked-issue-node-id != '' && steps.compute.outputs.linked-issue-status != ''
83-
uses: php-fast-forward/.github/.github/actions/project-board/sync-status@task/2-extract-shared-workflows
135+
uses: ./.fast-forward-actions/.github/actions/project-board/sync-status
84136
with:
85137
organization: ${{ github.repository_owner }}
86138
project: ${{ needs.resolve-project.outputs.project_number }}
@@ -92,10 +144,13 @@ jobs:
92144
if: github.event_name == 'pull_request_review' && needs.resolve-project.outputs.project_number != ''
93145
runs-on: ubuntu-latest
94146
steps:
147+
- *resolve_shared_action_ref
148+
- *checkout_shared_action_source
149+
95150
- id: compute
96-
uses: php-fast-forward/.github/.github/actions/project-board/resolve-review-status@task/2-extract-shared-workflows
151+
uses: ./.fast-forward-actions/.github/actions/project-board/resolve-review-status
97152

98-
- uses: php-fast-forward/.github/.github/actions/project-board/sync-status@task/2-extract-shared-workflows
153+
- uses: ./.fast-forward-actions/.github/actions/project-board/sync-status
99154
with:
100155
organization: ${{ github.repository_owner }}
101156
project: ${{ needs.resolve-project.outputs.project_number }}

.github/workflows/auto-resolve-conflicts.yml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ concurrency:
4141

4242
env:
4343
FORCE_COLOR: '1'
44+
FAST_FORWARD_ACTIONS_REPOSITORY: php-fast-forward/.github
45+
FAST_FORWARD_ACTIONS_REF: ${{ github.repository != 'php-fast-forward/.github' && vars.FAST_FORWARD_ACTIONS_REF || '' }}
4446

4547
jobs:
4648
resolve_predictable_conflicts:
@@ -56,15 +58,53 @@ jobs:
5658
- uses: actions/checkout@v6
5759
with:
5860
fetch-depth: 0
61+
62+
- name: Resolve shared action ref
63+
id: shared_actions
64+
shell: bash
65+
env:
66+
GH_TOKEN: ${{ github.token }}
67+
CURRENT_REF: ${{ github.head_ref || github.ref_name }}
68+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
69+
run: |
70+
set -euo pipefail
71+
72+
if [ -n "${FAST_FORWARD_ACTIONS_REF}" ]; then
73+
ref="${FAST_FORWARD_ACTIONS_REF}"
74+
elif [ "${GITHUB_REPOSITORY}" = "${FAST_FORWARD_ACTIONS_REPOSITORY}" ]; then
75+
if [ "${GITHUB_EVENT_NAME}" = "pull_request_target" ] && [ -n "${BASE_SHA:-}" ]; then
76+
ref="${BASE_SHA}"
77+
else
78+
ref="${CURRENT_REF:-main}"
79+
fi
80+
else
81+
ref="$(gh api "repos/${FAST_FORWARD_ACTIONS_REPOSITORY}/releases/latest" --jq .tag_name 2>/dev/null || true)"
82+
83+
if [ -z "${ref}" ] || [ "${ref}" = "null" ]; then
84+
ref="main"
85+
fi
86+
fi
87+
88+
echo "ref=${ref}" >> "${GITHUB_OUTPUT}"
89+
90+
- name: Checkout shared action source
91+
uses: actions/checkout@v6
92+
with:
93+
repository: ${{ env.FAST_FORWARD_ACTIONS_REPOSITORY }}
94+
ref: ${{ steps.shared_actions.outputs.ref }}
95+
path: .fast-forward-actions
96+
sparse-checkout: |
97+
.github/actions
98+
5999
- name: Setup PHP and install dependencies
60-
uses: php-fast-forward/.github/.github/actions/php/setup-composer@task/2-extract-shared-workflows
100+
uses: ./.fast-forward-actions/.github/actions/php/setup-composer
61101
with:
62102
php-version: '8.3'
63103
root-version: ${{ env.AUTO_RESOLVE_ROOT_VERSION }}
64104
install-options: --prefer-dist --no-progress --no-interaction --no-plugins --no-scripts
65105

66106
- name: Resolve predictable pull request conflicts
67-
uses: php-fast-forward/.github/.github/actions/github/resolve-predictable-conflicts@task/2-extract-shared-workflows
107+
uses: ./.fast-forward-actions/.github/actions/github/resolve-predictable-conflicts
68108
with:
69109
base-ref: ${{ env.BASE_REF }}
70110
pull-request-number: ${{ env.PULL_REQUEST_NUMBER }}

0 commit comments

Comments
 (0)