Skip to content

Commit 8be790e

Browse files
committed
git-artifacts: allow running in private forks
On GitHub, forks of public repositories cannot be private, of course, but a fork can be created other than by clicking GitHub's `Fork` button... Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 838dc50 commit 8be790e

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

.github/actions/check-run-action/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ inputs:
99
required: true
1010
owner:
1111
description: 'The owner of the target repository'
12-
default: 'git-for-windows'
1312
repo:
1413
description: 'The name of the target repository'
1514
rev:

.github/workflows/git-artifacts.yml

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,53 @@ jobs:
5757
steps:
5858
- name: clone git-for-windows-automation
5959
uses: actions/checkout@v5
60+
- name: configure token
61+
if: github.repository_visibility == 'private'
62+
id: token
63+
uses: actions/github-script@v7
64+
with:
65+
result-encoding: string
66+
script: |
67+
const fs = require('fs')
68+
if (!fs.existsSync(process.env.HOME)) fs.mkdirSync(process.env.HOME)
69+
const { callGit, getPushAuthorizationHeader } = require('./repository-updates.js')
70+
for (const repo of [
71+
'build-extra',
72+
'git',
73+
'git-sdk-${{ env.ARCHITECTURE == 'x86_64' && '64' || (env.ARCHITECTURE == 'aarch64' && 'arm64' || '32') }}',
74+
'MINGW-packages'
75+
]) {
76+
const header = await getPushAuthorizationHeader(
77+
console,
78+
core.setSecret,
79+
${{ secrets.GH_APP_ID }},
80+
${{ toJSON(secrets.GH_APP_PRIVATE_KEY) }},
81+
process.env.OWNER,
82+
repo
83+
)
84+
console.log(callGit(['config', '--global', `http.https://github.com/${process.env.OWNER}/${repo}.extraHeader`, header]))
85+
}
86+
87+
// return an access token for use in the "wait if workflow run has not finished yet" step
88+
if (process.env.EXISTING_GIT_TAG) return ''
89+
const getAppInstallationId = require('./get-app-installation-id')
90+
const installationId = await getAppInstallationId(
91+
console,
92+
${{ secrets.GH_APP_ID }},
93+
${{ toJSON(secrets.GH_APP_PRIVATE_KEY) }},
94+
context.repo.owner,
95+
context.repo.repo
96+
)
97+
98+
const getInstallationAccessToken = require('./get-installation-access-token')
99+
const { token: accessToken } = await getInstallationAccessToken(
100+
console,
101+
${{ secrets.GH_APP_ID }},
102+
${{ toJSON(secrets.GH_APP_PRIVATE_KEY) }},
103+
installationId
104+
)
105+
core.setSecret(accessToken)
106+
return accessToken
60107
- name: Construct bundle-artifacts from existing tag
61108
id: handle-existing-git-tag
62109
if: env.EXISTING_GIT_TAG != ''
@@ -109,7 +156,7 @@ jobs:
109156
const { waitForWorkflowRunToFinish } = require('./workflow-runs')
110157
await waitForWorkflowRunToFinish(
111158
console,
112-
'${{ secrets.GITHUB_TOKEN }}',
159+
'${{ steps.token.outputs.result || secrets.GITHUB_TOKEN }}',
113160
context.repo.owner,
114161
context.repo.repo,
115162
process.env.TAG_GIT_WORKFLOW_RUN_ID
@@ -119,6 +166,7 @@ jobs:
119166
if: env.TAG_GIT_WORKFLOW_RUN_ID != ''
120167
id: get-bundle-artifacts-url
121168
with:
169+
github-token: ${{ steps.token.outputs.result || secrets.GITHUB_TOKEN }}
122170
script: |
123171
if (process.env.EXISTING_GIT_TAG) {
124172
throw new Error('tag_git_workflow_run_id cannot be used with existing_git_tag!')
@@ -215,7 +263,7 @@ jobs:
215263
run:
216264
USER_NAME="${{github.actor}}" &&
217265
USER_EMAIL="${{github.actor}}@users.noreply.github.com" &&
218-
mkdir "$HOME" &&
266+
mkdir -p "$HOME" &&
219267
git config --global user.name "$USER_NAME" &&
220268
git config --global user.email "$USER_EMAIL" &&
221269
echo "PACKAGER=$USER_NAME <$USER_EMAIL>" >> $GITHUB_ENV
@@ -328,6 +376,7 @@ jobs:
328376
with:
329377
app-id: ${{ secrets.GH_APP_ID }}
330378
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
379+
owner: ${{ env.OWNER }}
331380
append-text: 'About to build the `${{env.MINGW_PACKAGE_PREFIX}}-git` package'
332381
- name: Build ${{env.MINGW_PACKAGE_PREFIX}}-git
333382
timeout-minutes: 60
@@ -385,6 +434,7 @@ jobs:
385434
with:
386435
app-id: ${{ secrets.GH_APP_ID }}
387436
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
437+
owner: ${{ env.OWNER }}
388438
append-text: 'The `${{env.MINGW_PACKAGE_PREFIX}}-git` package was built successfully'
389439
- name: Publish ${{env.MINGW_PACKAGE_PREFIX}}-git
390440
uses: actions/upload-artifact@v4
@@ -401,6 +451,7 @@ jobs:
401451
with:
402452
app-id: ${{ secrets.GH_APP_ID }}
403453
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
454+
owner: ${{ env.OWNER }}
404455
append-text: "${{ format('Completed: {0}', job.status) }}."
405456
conclusion: ${{ job.status }}
406457
artifacts:
@@ -441,6 +492,25 @@ jobs:
441492
with:
442493
flavor: build-installers
443494
architecture: ${{env.ARCHITECTURE}}
495+
- name: configure token
496+
if: github.repository_visibility == 'private'
497+
uses: actions/github-script@v7
498+
with:
499+
script: |
500+
const fs = require('fs')
501+
if (!fs.existsSync(process.env.HOME)) fs.mkdirSync(process.env.HOME)
502+
const { callGit, getPushAuthorizationHeader } = require('./repository-updates.js')
503+
for (const repo of ['build-extra', 'git-sdk-${{ env.ARCHITECTURE == 'x86_64' && '64' || (env.ARCHITECTURE == 'aarch64' && 'arm64' || '32') }}']) {
504+
const header = await getPushAuthorizationHeader(
505+
console,
506+
core.setSecret,
507+
${{ secrets.GH_APP_ID }},
508+
${{ toJSON(secrets.GH_APP_PRIVATE_KEY) }},
509+
process.env.OWNER,
510+
repo
511+
)
512+
console.log(callGit(['config', '--global', `http.https://github.com/${process.env.OWNER}/${repo}.extraHeader`, header]))
513+
}
444514
- name: Set up Git for Windows SDK ${{ env.architecture }} (${{ env.RELEASE_BRANCH }})
445515
if: env.OWNER != 'git-for-windows' || env.RELEASE_BRANCH != 'main'
446516
shell: bash
@@ -456,7 +526,7 @@ jobs:
456526
run:
457527
USER_NAME="${{github.actor}}" &&
458528
USER_EMAIL="${{github.actor}}@users.noreply.github.com" &&
459-
mkdir "$HOME" &&
529+
mkdir -p "$HOME" &&
460530
git config --global user.name "$USER_NAME" &&
461531
git config --global user.email "$USER_EMAIL"
462532
- name: Clone and update build-extra
@@ -579,6 +649,7 @@ jobs:
579649
with:
580650
app-id: ${{ secrets.GH_APP_ID }}
581651
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
652+
owner: ${{ env.OWNER }}
582653
append-text: 'Built ${{ matrix.artifact.name }}'
583654
- name: Run the installer
584655
if: matrix.artifact.name == 'installer'
@@ -627,6 +698,7 @@ jobs:
627698
with:
628699
app-id: ${{ secrets.GH_APP_ID }}
629700
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
701+
owner: ${{ env.OWNER }}
630702
append-text: "${{ format('Completed: {0}', job.status) }}."
631703
conclusion: ${{ job.status }}
632704
sha256sums:
@@ -661,5 +733,6 @@ jobs:
661733
with:
662734
app-id: ${{ secrets.GH_APP_ID }}
663735
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
736+
owner: ${{ env.OWNER }}
664737
append-text: "${{ job.status == 'success' && 'Done!' || format('Completed: {0}', job.status) }}."
665738
conclusion: ${{ job.status }}

0 commit comments

Comments
 (0)