Skip to content

Commit bc37909

Browse files
committed
deploy: allow deploying in forks
It would be nice if we could deploy the Azure Function contingent on the presence of the `AZURE_CLIENT_ID` secret. However, this is not possible in GitHub workflows: the job-level `if:` conditions lack access to the `secrets` context. Strangely enough, they _do_ have access to the `vars` context... To successfully deploy the Azure Function, it needs to know which `gitgitgadget-workflows` fork to target when triggering workflow runs, anyway, so let's _require_ a repository variable called `DEPLOY_WITH_WORKFLOWS` that specifies that fork in the form `<org>/gitgitgadget-workflows`. Note that such a `gitgitgadget-workflows` fork _must_ have the `config` branch, with a `gitgitgadget-config.json` file that contains the corresponding project configuration; The `deploy` workflow will retrieve this configuration and overwrite `gitgitgadget-config.json` with it, augmenting the `workflowsRepo` information on the fly. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a1a0dde commit bc37909

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,39 @@ permissions:
1515

1616
jobs:
1717
deploy:
18-
if: github.event.repository.fork == false
18+
if: github.event.repository.fork == false || vars.DEPLOY_WITH_WORKFLOWS != ''
1919
environment: deploy-to-azure
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v5
23+
- name: parse DEPLOY_WITH_WORKFLOWS
24+
if: vars.DEPLOY_WITH_WORKFLOWS != '' && contains(vars.DEPLOY_WITH_WORKFLOWS, '/')
25+
id: parsed
26+
env:
27+
WORKFLOWS_REPO: '${{ vars.DEPLOY_WITH_WORKFLOWS }}'
28+
run: |
29+
echo "owner=${WORKFLOWS_REPO%%/*}" >>$GITHUB_OUTPUT &&
30+
echo "name=${WORKFLOWS_REPO#*/}" >>$GITHUB_OUTPUT
31+
- name: retrieve `vars.CONFIG` from workflows repo
32+
if: vars.DEPLOY_WITH_WORKFLOWS != ''
33+
env:
34+
WORKFLOWS_REPO: '${{ vars.DEPLOY_WITH_WORKFLOWS }}'
35+
GH_TOKEN: ${{ steps.workflows-repo-token.outputs.token || secrets.GITHUB_TOKEN }}
36+
run: |
37+
set -x &&
38+
if ! curl -fLO https://github.com/"$WORKFLOWS_REPO"/raw/config/gitgitgadget-config.json
39+
then
40+
echo "::error::Could not retrieve 'gitgitgadget-config.json' from the 'config' branch of $WORKFLOWS_REPO"
41+
exit 1
42+
fi &&
43+
jq '. + {
44+
"workflowsRepo": {
45+
"owner": "${{ steps.parsed.outputs.owner }}",
46+
"name": "${{ steps.parsed.outputs.name }}"
47+
}
48+
}' <gitgitgadget-config.json >GitGitGadget/gitgitgadget-config.json &&
49+
echo "Using the following configuration:" &&
50+
cat GitGitGadget/gitgitgadget-config.json
2351
- name: 'Login via Azure CLI'
2452
uses: azure/login@v2
2553
with:

0 commit comments

Comments
 (0)