Skip to content

Commit d790559

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 fork _must_ have the `CONFIG` repository variable 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 56843fb commit d790559

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,24 @@ 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: retrieve `vars.CONFIG` from workflows repo
24+
if: vars.DEPLOY_WITH_WORKFLOWS != ''
25+
env:
26+
WORKFLOWS_REPO: '${{ vars.DEPLOY_WITH_WORKFLOWS }}'
27+
GH_TOKEN: ${{ github.token }}
28+
run: |
29+
WORKFLOWS_OWNER="${WORKFLOWS_REPO%%/*}" &&
30+
WORKFLOWS_NAME="${WORKFLOWS_REPO#*/}" &&
31+
gh variable get CONFIG --repo "$WORKFLOWS_REPO" |
32+
jq '. + { "workflowsRepo": { "owner": "'"$WORKFLOWS_OWNER"'", "name": "'"$WORKFLOWS_NAME"'" } }' \
33+
>GitGitGadget/gitgitgadget-config.json &&
34+
echo "Using the following configuration:" &&
35+
cat GitGitGadget/gitgitgadget-config.json
2336
- name: 'Login via Azure CLI'
2437
uses: azure/login@v2
2538
with:

0 commit comments

Comments
 (0)