Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,51 @@ jobs:
private-key: '${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
owner: '${{ env.FLUX_OWNER }}'
repositories: '${{ env.FLUX_REPO }}'

- name: Checkout Flux repo
uses: actions/checkout@v4
with:
repository: '${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
token: '${{ steps.app-token.outputs.token }}'
path: flux-repo
persist-credentials: false

- name: Export PR ID
run: 'echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
shell: bash
run: 'echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'

- name: Ensure template exists
shell: bash
run: >
T="flux-repo/pr-template/${APP_NAME}"

[[ -d "$T" ]] || { echo "Missing $T"; exit 1; }

[[ $(find "$T" -type f | wc -l) -gt 0 ]] || { echo "No files in $T";
exit 1; }
shell: bash

- name: Render & copy template
shell: bash
run: |
SRC="flux-repo/pr-template/${APP_NAME}"
DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
mkdir -p "$DST"
cp -r "$SRC/." "$DST/"
find "$DST" -type f -print0 \
| xargs -0 -n1 sed -i "s|@PR-ID@|${PR_ID}|g"
shell: bash

- name: Sanity‑check rendered output
shell: bash
run: >
E=$(find "flux-repo/pr-template/${APP_NAME}" -type f | wc -l)

G=$(find "flux-repo/deployments/prs-${APP_NAME}/${PR_ID}" -type f | wc
-l)

(( G == E )) || { echo "Expected $E files, got $G"; exit 1; }
shell: bash

- name: Commit & push creation
shell: bash
run: >
cd flux-repo

Expand All @@ -84,13 +91,22 @@ jobs:
git remote set-url origin \
https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
git push origin HEAD:main
shell: bash

- name: Comment preview URL on PR
uses: thollander/actions-comment-pull-request@v3
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
pr-number: '${{ github.event.pull_request.number }}'
comment-tag: 'pr-preview'
create-if-not-exists: 'true'
message: |
⚙️ Preview environment for PR #${{ env.PR_ID }} is available at:
https://pr-${{ env.PR_ID }}.${{ env.APP_NAME }}.coderamp.dev/

remove-pr-env:
if: >-
(github.event.action == 'unlabeled' && github.event.label.name ==
'deploy-pr-temp-env') || (github.event.action == 'closed' &&
github.event.pull_request.merged == true)
'deploy-pr-temp-env') || (github.event.action == 'closed')
runs-on: ubuntu-latest
steps:
- name: Create GitHub App token
Expand All @@ -101,17 +117,21 @@ jobs:
private-key: '${{ secrets.CR_APP_CI_PRIVATE_KEY }}'
owner: '${{ env.FLUX_OWNER }}'
repositories: '${{ env.FLUX_REPO }}'

- name: Checkout Flux repo
uses: actions/checkout@v4
with:
repository: '${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}'
token: '${{ steps.app-token.outputs.token }}'
path: flux-repo
persist-credentials: false

- name: Export PR ID
run: 'echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'
shell: bash
run: 'echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV'

- name: Remove deployed directory
shell: bash
run: |
DST="flux-repo/deployments/prs-${APP_NAME}/${PR_ID}"
if [[ -d "$DST" ]]; then
Expand All @@ -120,8 +140,9 @@ jobs:
else
echo "⏭️ Nothing to delete at $DST"
fi
shell: bash

- name: Commit & push deletion
shell: bash
run: >
cd flux-repo

Expand All @@ -138,4 +159,13 @@ jobs:
git remote set-url origin \
https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git
git push origin HEAD:main
shell: bash

- name: Comment preview URL on PR
uses: thollander/actions-comment-pull-request@v3
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
pr-number: '${{ github.event.pull_request.number }}'
comment-tag: 'pr-preview'
create-if-not-exists: 'true'
message: |
⚙️ Preview environment was undeployed.
Loading