Fixes for docs-staging-x repos workflows (#53864) · github/docs@d79c129 · GitHub
Skip to content

Commit d79c129

Browse files
authored
Fixes for docs-staging-x repos workflows (#53864)
1 parent 6a8499c commit d79c129

12 files changed

Lines changed: 264 additions & 69 deletions

File tree

‎.github/workflows/sync-staging-repo-files.yml‎

Lines changed: 44 additions & 15 deletions

‎.github/workflows/update-docs-staging-x-repo.yml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
types: [labeled]
1919

2020
permissions:
21-
contents: read
21+
contents: write
2222

2323
jobs:
2424
dispatch-sha:
@@ -72,6 +72,13 @@ jobs:
7272
# Get the commit SHA from the pull request head
7373
COMMIT_SHA="${{ github.event.pull_request.head.sha }}"
7474
75+
# Update the docs-staging-x branch to the latest SHA from the PR branch
76+
git config user.name "github-actions[bot]"
77+
git config user.email "github-actions[bot]@users.noreply.github.com"
78+
git checkout docs-staging-$STAGING_NUMBER || { echo "Failed to checkout docs-staging-$STAGING_NUMBER"; exit 1; }
79+
git reset --hard $COMMIT_SHA || { echo "Git reset failed"; exit 1; }
80+
git push origin docs-staging-$STAGING_NUMBER --force || { echo "Git push failed"; exit 1; }
81+
7582
else
7683
echo "Event type $EVENT_TYPE not supported."
7784
echo "should_dispatch=false" >> $GITHUB_OUTPUT

‎src/deployments/staging/.github/workflows/deploy-on-repo-dispatch.yml‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,55 @@ jobs:
2222
- name: Checkout Repository
2323
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2424
with:
25-
fetch-depth: 0 # Ensure full history for PR creation
25+
fetch-depth: 2
2626

27-
# Extract SHA from the dispatch payload
27+
# Extract SHA from the dispatch payload and set it as an output
2828
- name: Set SHA from Payload
2929
id: set_sha
30-
run: echo "SHA=${{ github.event.client_payload.SHA }}" >> $GITHUB_ENV
30+
run: echo "SHA=${{ github.event.client_payload.SHA }}" >> $GITHUB_OUTPUT
3131

3232
# Update the .env file with the new SHA
3333
- name: Update .env File
3434
run: |
35+
SHA=${{ steps.set_sha.outputs.SHA }}
3536
if grep -q "^SHA=" .env; then
3637
sed -i "s/^SHA=.*/SHA=${SHA}/" .env
3738
else
3839
echo "SHA=${SHA}" >> .env
40+
fi
3941
4042
- name: Commit Changes to new branch
43+
id: commit_changes
4144
run: |
4245
BRANCH_NAME=update-sha-${{ github.run_id }}
4346
git config user.name "github-actions[bot]"
4447
git config user.email "github-actions[bot]@users.noreply.github.com"
4548
git checkout -b $BRANCH_NAME
4649
git add .env
47-
git commit -m "Update SHA to ${{ env.SHA }}"
48-
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
50+
git commit -m "Update SHA to ${{ steps.set_sha.outputs.SHA }}"
51+
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
4952
5053
- name: Push Branch
51-
run: git push origin ${{ env.BRANCH_NAME }}
54+
run: git push origin ${{ steps.commit_changes.outputs.BRANCH_NAME }}
5255

56+
# Create a Pull Request and set the PR URL as an output
5357
- name: Create Pull Request
5458
id: create_pr
5559
env:
5660
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5761
run: |
5862
PR_URL=$(gh pr create \
59-
--title "Update SHA to ${{ env.SHA }}" \
60-
--body "This PR updates the SHA in the \`.env\` file to \`${{ env.SHA }}\`." \
63+
--title "Update SHA to ${{ steps.set_sha.outputs.SHA }}" \
64+
--body "This PR updates the SHA in the \`.env\` file to \`${{ steps.set_sha.outputs.SHA }}\`." \
6165
--base main \
62-
--head ${{ env.BRANCH_NAME }} \
63-
--json url \
64-
--jq .url)
65-
echo "PR_URL=$PR_URL" >> $GITHUB_ENV
66+
--head ${{ steps.commit_changes.outputs.BRANCH_NAME }} \
67+
)
68+
echo "PR_URL=${PR_URL}" >> $GITHUB_OUTPUT
6669
70+
# Merge the Pull Request
6771
- name: Merge Pull Request
6872
env:
6973
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7074
run: |
71-
PR_NUMBER=$(gh pr view $PR_URL --json number --jq .number)
72-
gh pr merge $PR_NUMBER --merge --delete-branch --auto --squash --yes
75+
PR_NUMBER=$(gh pr view ${{ steps.create_pr.outputs.PR_URL }} --json number --jq .number)
76+
gh pr merge $PR_NUMBER --auto --squash
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: docs-staging-{{x}} Moda CI
2+
3+
# More info on CI actions setup can be found here:
4+
# https://github.com/github/ops/blob/master/docs/playbooks/build-systems/moving-moda-apps-from-bp-to-actions.md
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches-ignore:
10+
- 'gh-readonly-queue/**'
11+
merge_group:
12+
types: [checks_requested]
13+
14+
jobs:
15+
##########################
16+
# Add DOCS_BOT_PAT_READPUBLICKEY to vault-keys
17+
##########################
18+
set-vault-keys:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
modified_vault_keys: ${{ steps.modify_vault_keys.outputs.modified }}
22+
steps:
23+
- name: Set vault-keys output
24+
id: modify_vault_keys
25+
run: |
26+
if [ -z "${{ vars.VAULT_KEYS }}" ]; then
27+
echo "modified=DOCS_BOT_PAT_READPUBLICKEY" >> $GITHUB_OUTPUT
28+
else
29+
echo "modified=${{ vars.VAULT_KEYS }},DOCS_BOT_PAT_READPUBLICKEY" >> $GITHUB_OUTPUT
30+
fi
31+
32+
#############
33+
# Moda jobs
34+
#############
35+
moda-config-bundle:
36+
name: ${{ matrix.ci_job.job }}
37+
needs: set-vault-keys
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
ci_job: [{ 'job': 'docs-staging-{{x}}-moda-config-bundle' }]
42+
uses: github/internal-actions/.github/workflows/moda.yml@main
43+
with:
44+
ci-formatted-job-name: ${{ matrix.ci_job.job }}
45+
vault-keys: ${{ needs.set-vault-keys.outputs.modified_vault_keys }}
46+
secrets:
47+
dx-bot-token: ${{ secrets.INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN }}
48+
datadog-api-key: ${{ secrets.DATADOG_API_KEY }}
49+
50+
#############
51+
# Docker Image jobs
52+
#############
53+
docker-image:
54+
name: ${{ matrix.ci_job.job }}
55+
needs: set-vault-keys
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
ci_job: [{ 'job': 'docs-staging-{{x}}-docker-image' }]
60+
uses: github/internal-actions/.github/workflows/kube.yml@main
61+
with:
62+
ci-formatted-job-name: ${{ matrix.ci_job.job }}
63+
# Fetches the 'DOCS_BOT_PAT_READPUBLICKEY' secret from Vault to pass to the docker build environment as --secret id=DOCS_BOT_PAT_READPUBLICKEY,src=$(cat DOCS_BOT_PAT_READPUBLICKEY)
64+
vault-keys: ${{ needs.set-vault-keys.outputs.modified_vault_keys }}
65+
docker-build-env-secrets: 'DOCS_BOT_PAT_READPUBLICKEY'
66+
secrets:
67+
dx-bot-token: ${{ secrets.INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN }}
68+
datadog-api-key: ${{ secrets.DATADOG_API_KEY }}
69+
70+
#############
71+
# Docker Security jobs
72+
#############
73+
docker-security:
74+
name: ${{ matrix.ci_job.job }}
75+
needs: set-vault-keys
76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
ci_job: [{ 'job': 'docs-staging-{{x}}-docker-security' }]
80+
uses: github/internal-actions/.github/workflows/docker_security.yml@main
81+
with:
82+
ci-formatted-job-name: ${{ matrix.ci_job.job }}
83+
# Fetches the 'DOCS_BOT_PAT_READPUBLICKEY' secret from Vault to pass to the docker build environment as --secret id=DOCS_BOT_PAT_READPUBLICKEY,src=$(cat DOCS_BOT_PAT_READPUBLICKEY)
84+
vault-keys: ${{ needs.set-vault-keys.outputs.modified_vault_keys }}
85+
docker-build-env-secrets: 'DOCS_BOT_PAT_READPUBLICKEY'
86+
secrets:
87+
dx-bot-token: ${{ secrets.INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN }}
88+
datadog-api-key: ${{ secrets.DATADOG_API_KEY }}
89+
90+
permissions:
91+
actions: read
92+
checks: read
93+
contents: read
94+
statuses: read
95+
id-token: write

‎src/deployments/staging/README.example.md‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎src/deployments/staging/README.md‎

Lines changed: 10 additions & 6 deletions

0 commit comments

Comments
 (0)