|
| 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 | + FLUX_OWNER: ${{ github.repository_owner }} |
| 18 | + FLUX_REPO: ${{ secrets.CR_FLUX_REPO }} |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Create GitHub App token |
| 22 | + uses: actions/create-github-app-token@v2 |
| 23 | + id: app-token |
| 24 | + with: |
| 25 | + app-id: ${{ secrets.CR_APP_CI_APP_ID }} |
| 26 | + private-key: ${{ secrets.CR_APP_CI_PRIVATE_KEY }} |
| 27 | + owner: ${{ env.FLUX_OWNER }} |
| 28 | + repositories: ${{ env.FLUX_REPO }} |
| 29 | + |
| 30 | + - name: Checkout Flux repo |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + repository: ${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }} |
| 34 | + token: ${{ steps.app-token.outputs.token }} |
| 35 | + path: flux-repo |
| 36 | + persist-credentials: false |
| 37 | + |
| 38 | + - name: Export PR ID |
| 39 | + run: echo "PR_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV |
| 40 | + shell: bash |
| 41 | + |
| 42 | + - name: Ensure template exists |
| 43 | + run: | |
| 44 | + T="flux-repo/pr-template/${APP_NAME}" |
| 45 | + [[ -d "$T" ]] || { echo "Missing $T"; exit 1; } |
| 46 | + [[ $(find "$T" -type f | wc -l) -gt 0 ]] || { echo "No files in $T"; exit 1; } |
| 47 | + shell: bash |
| 48 | + |
| 49 | + - name: Render & copy template |
| 50 | + run: | |
| 51 | + SRC="flux-repo/pr-template/${APP_NAME}" |
| 52 | + DST="flux-repo/deployments/prs-gitingest/${PR_ID}" |
| 53 | + mkdir -p "$DST" |
| 54 | + cp -r "$SRC/." "$DST/" |
| 55 | + find "$DST" -type f -print0 \ |
| 56 | + | xargs -0 -n1 sed -i "s|@PR-ID@|${PR_ID}|g" |
| 57 | + shell: bash |
| 58 | + |
| 59 | + - name: Sanity‑check rendered output |
| 60 | + run: | |
| 61 | + E=$(find "flux-repo/pr-template/${APP_NAME}" -type f | wc -l) |
| 62 | + G=$(find "flux-repo/deployments/prs-gitingest/${PR_ID}" -type f | wc -l) |
| 63 | + (( G == E )) || { echo "Expected $E files, got $G"; exit 1; } |
| 64 | + shell: bash |
| 65 | + |
| 66 | + - name: Commit & push to Flux repo |
| 67 | + run: | |
| 68 | + cd flux-repo |
| 69 | + git config user.name "${{ steps.app-token.outputs.app-slug }}[bot]" |
| 70 | + git config user.email "${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com" |
| 71 | + git add . |
| 72 | + git commit -m "chore(prs-gitingest): create temp env for PR #${{ env.PR_ID }} [skip ci]" || echo "Nothing to commit" |
| 73 | + # embed token into remote URL for push: |
| 74 | + git remote set-url origin \ |
| 75 | + https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ env.FLUX_OWNER }}/${{ env.FLUX_REPO }}.git |
| 76 | + git push origin HEAD:main |
| 77 | + shell: bash |
0 commit comments