Skip to content

Commit 5101709

Browse files
committed
update metadata sync job to use VP Metadata Sync GitHub App when possible
1 parent 5ade466 commit 5101709

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

.github/workflows/metadata-docs.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This GH action has the goal to fetch the pattern-metadata.yaml file (if existing)
22
# and output all of its flattened yaml structure into asciidoc variables for the pattern
3-
#
3+
#
44
# It needs a secret called DOCS_TOKEN to be set in the pattern's repository
55
# that calls this GH action. It has to be a PAT token with the following
66
# permissions on the `validatedpatterns/docs` repository
@@ -20,15 +20,23 @@ name: Update docs from pattern's metadata
2020
on:
2121
workflow_call:
2222
secrets:
23+
METADATA_SYNC_PRIVATE_KEY:
24+
required: false
25+
description: The private key for the Validated Patterns Metadata Sync app (must be set if DOCS_TOKEN is not)
2326
DOCS_TOKEN:
2427
required: false
25-
description: The token used to create a PR in the docs repository
28+
description: PAT with read/write (content and PRs) for validatedpatterns/docs repo (must be set if METADATA_SYNC_PRIVATE_KEY is not)
2629
inputs:
2730
DOCS_BRANCH:
2831
description: "Branch of the docs git repo to use"
2932
required: false
3033
type: string
3134
default: "main"
35+
METADATA_SYNC_APP_ID:
36+
description: "Validated Patterns Metadata Sync app id"
37+
required: false
38+
type: string
39+
default: "3329715"
3240

3341
env:
3442
DOCS_DIR: docs
@@ -74,13 +82,32 @@ jobs:
7482
} >> "${GITHUB_ENV}"
7583
working-directory: ${{ env.PATTERN_DIR }}
7684

85+
- name: Generate token with Metadata Sync GitHub App
86+
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
87+
id: app-token
88+
with:
89+
app-id: ${{ vars.METADATA_SYNC_APP_ID }}
90+
private-key: ${{ secrets.METADATA_SYNC_PRIVATE_KEY }}
91+
owner: validatedpatterns
92+
repositories: docs
93+
continue-on-error: true
94+
95+
- name: Resolve Documentation Token
96+
# Use App token if available, else fall back to the legacy secret
97+
run: |
98+
if [ -n "${{ steps.app-token.outputs.token }}" ]; then
99+
echo "FINAL_TOKEN=${{ steps.app-token.outputs.token }}" >> $GITHUB_ENV
100+
else
101+
echo "FINAL_TOKEN=${{ secrets.DOCS_TOKEN }}" >> $GITHUB_ENV
102+
fi
103+
77104
- name: Checkout docs repository
78105
uses: actions/checkout@v6
79106
with:
80107
path: ${{ env.DOCS_DIR }}
81108
repository: ${{ env.DOCS_REPO }}
82109
ref: ${{ inputs.DOCS_BRANCH }}
83-
token: ${{ secrets.DOCS_TOKEN }}
110+
token: ${{ env.FINAL_TOKEN }}
84111

85112
- name: Template the cluster variables on to the patterns-variables .adoc file
86113
run: |-
@@ -104,4 +131,4 @@ jobs:
104131
gh pr edit -B "${{ inputs.DOCS_BRANCH }}" --title 'Cluster variables change for ${{ env.PATTERN }}' --body 'Created by Github action'
105132
working-directory: ${{ env.DOCS_DIR }}
106133
env:
107-
GITHUB_TOKEN: ${{ secrets.DOCS_TOKEN }}
134+
GITHUB_TOKEN: ${{ env.FINAL_TOKEN }}

0 commit comments

Comments
 (0)