Skip to content

Commit 42cf39e

Browse files
authored
Replace GHA token in workflow to trigger api-go update (#416)
1 parent 89d8830 commit 42cf39e

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

.github/workflows/trigger-api-go-update.yml

+50-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ on:
55
branches:
66
- master
77
workflow_dispatch:
8+
inputs:
9+
branch:
10+
description: "Branch in api-go repo to trigger update protos (default: master)"
11+
required: true
12+
default: master
813

914
jobs:
1015
notify:
@@ -16,14 +21,51 @@ jobs:
1621
shell: bash
1722

1823
steps:
24+
- name: Generate token
25+
id: generate_token
26+
uses: actions/create-github-app-token@v1
27+
with:
28+
app-id: ${{ secrets.TEMPORAL_CICD_APP_ID }}
29+
private-key: ${{ secrets.TEMPORAL_CICD_PRIVATE_KEY }}
30+
owner: ${{ github.repository_owner }}
31+
repositories: api-go # generate a token with permissions to trigger GHA in api-go repo
32+
33+
- name: Prepare inputs
34+
id: prepare_inputs
35+
run: |
36+
case "${{ github.event_name }}" in
37+
"push")
38+
BRANCH=${{ github.event.ref }}
39+
BRANCH=${BRANCH#refs/heads/}
40+
COMMIT_AUTHOR=${{ toJSON(github.event.head_commit.author.name) }}
41+
COMMIT_AUTHOR_EMAIL=${{ toJSON(github.event.head_commit.author.email) }}
42+
COMMIT_MESSAGE=${{ toJSON(github.event.head_commit.message) }}
43+
;;
44+
45+
"workflow_dispatch")
46+
BRANCH="${{ github.event.inputs.branch }}"
47+
COMMIT_AUTHOR="Temporal Data"
48+
COMMIT_AUTHOR_EMAIL="[email protected]"
49+
COMMIT_MESSAGE="Update proto"
50+
;;
51+
esac
52+
53+
echo "BRANCH=${BRANCH}" >> $GITHUB_OUTPUT
54+
echo "COMMIT_AUTHOR=${COMMIT_AUTHOR}" >> $GITHUB_OUTPUT
55+
echo "COMMIT_AUTHOR_EMAIL=${COMMIT_AUTHOR_EMAIL}" >> $GITHUB_OUTPUT
56+
echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_OUTPUT
57+
1958
- name: Dispatch api-go Github Action
2059
env:
21-
PAT: ${{ secrets.COMMANDER_DATA_TOKEN }}
22-
PARENT_REPO: temporalio/api-go
23-
PARENT_BRANCH: ${{ toJSON('master') }}
24-
WORKFLOW_ID: update-proto.yml
25-
COMMIT_AUTHOR: ${{ toJSON(github.event.head_commit.author.name) }}
26-
COMMIT_AUTHOR_EMAIL: ${{ toJSON(github.event.head_commit.author.email) }}
27-
COMMIT_MESSAGE: ${{ toJSON(github.event.head_commit.message) }}
60+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
61+
BRANCH: ${{ steps.prepare_inputs.outputs.BRANCH }}
62+
COMMIT_AUTHOR: ${{ steps.prepare_inputs.outputs.COMMIT_AUTHOR }}
63+
COMMIT_AUTHOR_EMAIL: ${{ steps.prepare_inputs.outputs.COMMIT_AUTHOR_EMAIL }}
64+
COMMIT_MESSAGE: ${{ steps.prepare_inputs.outputs.COMMIT_MESSAGE }}
2865
run: |
29-
curl -fL -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ env.PAT }}" https://api.github.com/repos/${{ env.PARENT_REPO }}/actions/workflows/${{ env.WORKFLOW_ID }}/dispatches -d '{"ref":'"$PARENT_BRANCH"', "inputs":{"commit_author":'"$COMMIT_AUTHOR"', "commit_author_email":'"$COMMIT_AUTHOR_EMAIL"', "commit_message":'"$COMMIT_MESSAGE"'}}'
66+
gh workflow run update-proto.yml -R https://github.com/temporalio/api-go \
67+
-r master \
68+
-f branch="${BRANCH}" \
69+
-f commit_author="${COMMIT_AUTHOR}" \
70+
-f commit_author_email="${COMMIT_AUTHOR_EMAIL}" \
71+
-f commit_message="${COMMIT_MESSAGE}"

0 commit comments

Comments
 (0)