Skip to content

Commit a7d2a0a

Browse files
authored
Merge pull request #1017 from IABTechLab/swi-UID2-6896-deploy-preview-via-pr
UID2-6896 Update deployPreview to merge PR via UID2SourceAdmin PAT #407
2 parents fb19437 + c41d417 commit a7d2a0a

1 file changed

Lines changed: 51 additions & 13 deletions

File tree

.github/workflows/deployPreview.yml

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ on:
77
#push:
88
#branches: []
99
workflow_dispatch:
10+
inputs:
11+
source_ref:
12+
description: "Ref of uid2docs to deploy as preview (branch name, tag, or full SHA). Defaults to main."
13+
type: string
14+
default: main
1015

1116
permissions:
1217
contents: read
@@ -21,18 +26,51 @@ concurrency:
2126
jobs:
2227
deploy:
2328
runs-on: ubuntu-latest
29+
environment: ci-auto-merge
2430
steps:
25-
- name: Checkout
26-
uses: actions/checkout@v4
27-
- name: Clone to preview folder (excluding actions)
28-
run: rsync -arv --delete --delete-excluded --exclude=".github" --exclude="preview-output" --exclude="preview-output" --exclude=".git" ./ preview-output/
29-
- name: Push to staging repository
30-
uses: cpina/github-action-push-to-another-repository@55306faa4ed53b815ae49e564af8cfb359d32ae2 # main
31-
env:
32-
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
31+
- name: Checkout source at requested ref
32+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
33+
with:
34+
ref: ${{ inputs.source_ref }}
35+
path: source
36+
persist-credentials: false
37+
38+
- name: Checkout target preview repo
39+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
3340
with:
34-
source-directory: 'preview-output'
35-
destination-github-username: 'UnifiedID2'
36-
destination-repository-name: 'uid2-docs-preview'
37-
target-branch: main
38-
target-directory: preview
41+
repository: UnifiedID2/uid2-docs-preview
42+
token: ${{ secrets.GH_MERGE_TOKEN }}
43+
path: preview-target
44+
45+
- name: Sync source into preview/ subdir of target
46+
run: |
47+
rsync -arv --delete --delete-excluded \
48+
--exclude=".github" \
49+
--exclude=".git" \
50+
source/ preview-target/preview/
51+
52+
- name: Resolve source SHA for traceability
53+
id: source-sha
54+
run: echo "sha=$(git -C source rev-parse HEAD)" >> "$GITHUB_OUTPUT"
55+
56+
- name: Create PR with sync changes
57+
id: cpr
58+
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
59+
with:
60+
path: preview-target
61+
token: ${{ secrets.GH_MERGE_TOKEN }}
62+
branch: ci-deploy-preview
63+
delete-branch: true
64+
commit-message: "[CI Pipeline] Deploy preview from ${{ github.repository }} ${{ inputs.source_ref }} @ ${{ steps.source-sha.outputs.sha }}"
65+
title: "[CI Pipeline] Deploy preview from ${{ github.repository }} ${{ inputs.source_ref }}"
66+
body: "Automated preview deployment from `${{ github.repository }}` ref `${{ inputs.source_ref }}` (SHA `${{ steps.source-sha.outputs.sha }}`)."
67+
68+
- name: Merge PR as UID2SourceAdmin
69+
if: steps.cpr.outputs.pull-request-number != ''
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GH_MERGE_TOKEN }}
72+
PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
73+
run: |
74+
gh api --method PUT \
75+
"repos/UnifiedID2/uid2-docs-preview/pulls/$PR_NUMBER/merge" \
76+
-f merge_method="merge"

0 commit comments

Comments
 (0)