Skip to content

Commit adf3f0e

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

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

.github/workflows/deploy-pr.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Deploy PR Temp Environment
2+
3+
on:
4+
pull_request:
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+
APP_NAME: gitingest
17+
18+
steps:
19+
- name: Create GitHub App token
20+
uses: actions/create-github-app-token@v2
21+
id: app-token
22+
with:
23+
app-id: ${{ secrets.CR_APP_CI_APP_ID }}
24+
private-key: ${{ secrets.CR_APP_CI_PRIVATE_KEY }}
25+
repositories: ${{ secrets.CR_FLUX_REPO }}
26+
27+
- name: Checkout Flux repo
28+
uses: actions/checkout@v4
29+
with:
30+
repository: ${{ secrets.CR_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+
# replace @PR-ID@ → actual PR_ID
52+
find "$DST" -type f -print0 \
53+
| xargs -0 -n1 sed -i "s|@PR-ID@|${PR_ID}|g"
54+
shell: bash
55+
56+
- name: Sanity‑check rendered output
57+
run: |
58+
E=$(find "flux-repo/pr-template/${APP_NAME}" -type f | wc -l)
59+
G=$(find "flux-repo/deployments/prs-gitingest/${PR_ID}" -type f | wc -l)
60+
(( G == E )) || { echo "Expected $E files, got $G"; exit 1; }
61+
shell: bash
62+
63+
- name: Commit & push to Flux repo
64+
run: |
65+
cd flux-repo
66+
git config user.name "${{ steps.app-token.outputs.app-slug }}[bot]"
67+
git config user.email "${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com"
68+
git add .
69+
git commit -m "chore(prs-gitingest): create temp env for PR #${{ env.PR_ID }} [skip ci]" || echo "Nothing to commit"
70+
# embed token into remote URL for push:
71+
git remote set-url origin \
72+
https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ secrets.CR_FLUX_REPO }}.git
73+
git push origin HEAD:main
74+
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)