Skip to content

Commit fb431d5

Browse files
committed
ci: add workflow for deploying temporary PR environments
1 parent 9ceaf6c commit fb431d5

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

.github/workflows/deploy-pr.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Deploy PR Temp Environment
2+
3+
on:
4+
pull_request_target:
5+
types: [labeled]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
deploy-pr-env:
13+
if: ${{ github.event.label.name == 'deploy-pr-temp-env' }}
14+
runs-on: ubuntu-latest
15+
env:
16+
FLUX_REPO: ${{ secrets.CR_FLUX_REPO }}
17+
APP_NAME: gitingest
18+
19+
steps:
20+
- name: Create GitHub App token
21+
uses: actions/create-github-app-token@v2
22+
id: app-token
23+
with:
24+
app-id: ${{ secrets.CR_APP_CI_APP_ID }}
25+
private-key: ${{ secrets.CR_APP_CI_PRIVATE_KEY }}
26+
27+
- name: Checkout Flux repo
28+
uses: actions/checkout@v4
29+
with:
30+
repository: ${{ env.FLUX_REPO }}
31+
token: ${{ steps.app-token.outputs.token }}
32+
path: flux-repo
33+
persist-credentials: false
34+
35+
- name: Export PR ID
36+
run: echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
37+
38+
- name: Ensure template exists
39+
run: |
40+
T="flux-repo/pr-template/${APP_NAME}"
41+
[[ -d "$T" ]] || { echo "Missing $T"; exit 1; }
42+
[[ $(find "$T" -type f | wc -l) -gt 0 ]] || { echo "No files in $T"; exit 1; }
43+
shell: bash
44+
45+
- name: Render & copy template
46+
run: |
47+
SRC="flux-repo/pr-template/${APP_NAME}"
48+
DST="flux-repo/deployments/PRs-gitingest/${PR_ID}"
49+
mkdir -p "$DST"
50+
cp -r "$SRC/." "$DST/"
51+
find "$DST" -type f -exec sed -i "s/\$PR-ID\$/${PR_ID}/g" {} +
52+
shell: bash
53+
54+
- name: Sanity‑check rendered output
55+
run: |
56+
E=$(find "flux-repo/pr-template/${APP_NAME}" -type f | wc -l)
57+
G=$(find "flux-repo/deployments/PRs-gitingest/${PR_ID}" -type f | wc -l)
58+
(( G == E )) || { echo "Expected $E files, got $G"; exit 1; }
59+
shell: bash
60+
61+
- name: Commit & push to Flux repo
62+
run: |
63+
cd flux-repo
64+
git config user.name "${{ steps.app-token.outputs.app-slug }}[bot]"
65+
git config user.email "${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com"
66+
git add .
67+
git commit -m "Create temp env for PR #${{ env.PR_ID }} [skip ci]" || echo "Nothing to commit"
68+
# embed token into remote URL for push:
69+
git remote set-url origin \
70+
https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_REPO }}.git
71+
git push origin HEAD:main
72+
shell: bash

.github/workflows/docker_image.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Build & Push Container
2+
23
on:
34
push:
45
branches:
@@ -16,8 +17,14 @@ concurrency:
1617
env:
1718
REGISTRY: ghcr.io
1819
IMAGE_NAME: ${{ github.repository }}
19-
# Set to 'true' to allow pushing container from pull requests with the label 'push-container'
20-
PUSH_FROM_PR: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'push-container') }}
20+
# Now allow pushing from PRs when either 'push-container' OR 'deploy-pr-temp-env' is present:
21+
PUSH_FROM_PR: >-
22+
${{ github.event_name == 'pull_request' &&
23+
(
24+
contains(github.event.pull_request.labels.*.name, 'push-container') ||
25+
contains(github.event.pull_request.labels.*.name, 'deploy-pr-temp-env')
26+
)
27+
}}
2128
2229
jobs:
2330
docker-build:

0 commit comments

Comments
 (0)