Deploy to Preview Site #117
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Preview Site | |
| on: | |
| # Add any branches that you want to auto-deploy on push here. | |
| # WARNING: If a branch is auto-deploying, it will overright any manual deployments. | |
| # Use with caution and warn anyone else that this branch is basically taking over the preview site! | |
| #push: | |
| #branches: [] | |
| workflow_dispatch: | |
| inputs: | |
| source_ref: | |
| description: "Ref of uid2docs to deploy as preview (branch name, tag, or full SHA). Defaults to main." | |
| type: string | |
| default: main | |
| permissions: | |
| contents: read | |
| #id-token: write | |
| # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
| # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
| concurrency: | |
| group: "preview" | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| environment: ci-auto-merge | |
| steps: | |
| - name: Checkout source at requested ref | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | |
| with: | |
| ref: ${{ inputs.source_ref }} | |
| path: source | |
| persist-credentials: false | |
| - name: Checkout target preview repo | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | |
| with: | |
| repository: UnifiedID2/uid2-docs-preview | |
| token: ${{ secrets.GH_MERGE_TOKEN }} | |
| path: preview-target | |
| - name: Sync source into preview/ subdir of target | |
| run: | | |
| rsync -arv --delete --delete-excluded \ | |
| --exclude=".github" \ | |
| --exclude=".git" \ | |
| source/ preview-target/preview/ | |
| - name: Resolve source SHA for traceability | |
| id: source-sha | |
| run: echo "sha=$(git -C source rev-parse HEAD)" >> "$GITHUB_OUTPUT" | |
| - name: Create PR with sync changes | |
| id: cpr | |
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 | |
| with: | |
| path: preview-target | |
| token: ${{ secrets.GH_MERGE_TOKEN }} | |
| branch: ci-deploy-preview | |
| delete-branch: true | |
| commit-message: "[CI Pipeline] Deploy preview from ${{ github.repository }} ${{ inputs.source_ref }} @ ${{ steps.source-sha.outputs.sha }}" | |
| title: "[CI Pipeline] Deploy preview from ${{ github.repository }} ${{ inputs.source_ref }}" | |
| body: "Automated preview deployment from `${{ github.repository }}` ref `${{ inputs.source_ref }}` (SHA `${{ steps.source-sha.outputs.sha }}`)." | |
| - name: Merge PR as UID2SourceAdmin | |
| if: steps.cpr.outputs.pull-request-number != '' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_MERGE_TOKEN }} | |
| PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }} | |
| run: | | |
| gh api --method PUT \ | |
| "repos/UnifiedID2/uid2-docs-preview/pulls/$PR_NUMBER/merge" \ | |
| -f merge_method="merge" |