Skip to content
Draft
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions .github/workflows/template-only-ci-test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Template CI Test PRs
run-name: ${{ github.workflow }} - ${{ inputs.action || github.event.pull_request.state }}

on:
workflow_dispatch:
inputs:
branch_name:
required: true
type: string
action:
type: choice
options:
- update
- close
default: update
pull_request:
paths:
- "**"
- "copier.yml"
pull_request_target:
types: [closed]

# all access is via `PLATFORM_BOT_GITHUB_TOKEN`
permissions: {}

jobs:
update:
name: " " # GitHub UI is noisy when calling reusable workflows, so use whitespace for name to reduce noise
uses: ./.github/workflows/template-only-create-or-update-test-pr.yml
if: (github.event_name == 'workflow_dispatch' && inputs.action == 'update') || github.event.pull_request.state == 'open'
with:
branch_name: ${{ inputs.branch_name || github.head_ref }}
project_repo: navapbc/platform-test
secrets:
access_token: ${{ secrets.PLATFORM_BOT_GITHUB_TOKEN }}

close:
if: (github.event_name == 'workflow_dispatch' && inputs.action == 'close') || github.event.pull_request.state == 'closed'
runs-on: ubuntu-latest
steps:
- name: Close test PR
env:
GITHUB_TOKEN: ${{ secrets.PLATFORM_BOT_GITHUB_TOKEN }}
BRANCH_NAME: ${{ inputs.branch_name || github.head_ref }}
run: |
gh pr close "${BRANCH_NAME}" --delete-branch --repo navapbc/platform-test
95 changes: 95 additions & 0 deletions .github/workflows/template-only-create-or-update-test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Template Test PR

on:
workflow_call:
inputs:
branch_name:
required: true
type: string
project_repo:
type: string
required: true
pr_body:
type: string
secrets:
access_token:
required: true

# all access is via the provided `access_token`
permissions: {}

env:
BRANCH_NAME: ${{ inputs.branch_name }}

jobs:
create-or-update-pr:
name: Create or update PR
runs-on: ubuntu-latest
steps:
- name: Checkout project repo
uses: actions/checkout@v4
with:
path: project-repo
repository: ${{ inputs.project_repo }}
token: ${{ secrets.access_token }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Install nava-platform CLI
run: pipx install --python "$(which python)" git+https://github.com/navapbc/platform-cli

- name: Configure git
working-directory: project-repo
run: |
git config user.name nava-platform-bot
git config user.email platform-admins@navapbc.com

- name: Set up PR branch
working-directory: project-repo
run: |
git checkout -b "${BRANCH_NAME}"

- name: Update infra template
working-directory: project-repo
run: nava-platform infra update --template-uri ${{ github.server_url }}/${{ github.repository }} --version "${BRANCH_NAME}" .

- name: Push changes to project repo
working-directory: project-repo
run: git push --force --set-upstream origin HEAD

- name: Check for existing PR
id: check-pr
working-directory: project-repo
env:
GITHUB_TOKEN: ${{ secrets.access_token }}
run: |
PR_URL="$(gh pr list --head "${BRANCH_NAME}" --state open --json url --jq .[].url)"
if [[ -n "${PR_URL}" ]]; then
echo "PR already exists -> ${PR_URL}"
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "PR does not exist (or is not open)"
echo "exists=false" >> "$GITHUB_OUTPUT"
fi

- name: Open Pull Request
if: ${{ steps.check-pr.outputs.exists != 'true' }}
working-directory: project-repo
env:
GITHUB_TOKEN: ${{ secrets.access_token }}
PR_BODY: ${{ inputs.pr_body }}
run: |
if [[ -n "${PR_BODY}" ]]; then
: # we're good
elif [[ -n "${{ github.event.pull_request.html_url }}" ]]; then
PR_BODY="${{ github.event.pull_request.html_url }}"
else
PR_BODY="${{ github.server_url }}/${{ github.repository }}/tree/${BRANCH_NAME}"
fi

gh pr create \
--body "${PR_BODY}" \
--title "Test Template PR: ${BRANCH_NAME}"