Create the workflows directory if it doesn’t already exist:
mkdir -p .github/workflows
Create a file .github/workflows/konnect.yaml with the following GitHub
Actions workflow definition:
name: Konnect APIOps
on:
workflow_dispatch:
pull_request:
branches: [main]
paths:
- konnect/**
- .github/workflows/konnect.yaml
push:
branches: [main]
paths:
- konnect/**
- .github/workflows/konnect.yaml
permissions:
contents: read
pull-requests: write
concurrency:
group: konnect-${{ github.ref }}
cancel-in-progress: false
jobs:
configure:
if: >-
((github.event_name == 'push' ||
github.event_name == 'workflow_dispatch') &&
github.ref == 'refs/heads/main') ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository &&
github.actor != 'dependabot[bot]')
runs-on: ubuntu-latest
env:
KONGCTL_DEFAULT_KONNECT_PAT: ${{ secrets.KONNECT_TOKEN }}
KONGCTL_DEFAULT_KONNECT_REGION: ${{ vars.KONNECT_REGION }}
NO_COLOR: '1'
steps:
- uses: actions/checkout@v7
- uses: kong/setup-kongctl@v1
with:
kongctl-version: >-
1.16.0
- name: Check configuration
run: |
: "${KONGCTL_DEFAULT_KONNECT_PAT:?Set the KONNECT_TOKEN secret}"
: "${KONGCTL_DEFAULT_KONNECT_REGION:?Set KONNECT_REGION}"
- name: Show diff
if: github.event_name == 'pull_request'
shell: bash
run: |
kongctl diff --mode apply -f konnect/portal.yaml -o text \
--region "$KONGCTL_DEFAULT_KONNECT_REGION" | tee diff.txt
{
echo '## Konnect configuration diff'
echo '```text'
cat diff.txt
echo '```'
} > comment.md
cat comment.md >> "$GITHUB_STEP_SUMMARY"
- name: Post diff comment
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: konnect-diff
path: comment.md
- name: Apply configuration
if: >-
github.ref == 'refs/heads/main' &&
(github.event_name == 'push' ||
github.event_name == 'workflow_dispatch')
run: |
kongctl apply -f konnect/portal.yaml --auto-approve -o text \
--region "$KONGCTL_DEFAULT_KONNECT_REGION"
The workflow installs the pinned kongctl version and does the following:
- On pull requests targeting
main: Compares configuration with live
Konnect state and posts a diff in the summary and an updating PR comment.
It doesn’t apply changes. pull-requests: write allows the comment.
- On pushes or manual runs on
main: Calculates a fresh plan and
applies it without prompting. Concurrency prevents overlapping applies.
Manual runs on other branches are skipped.
Only give trusted contributors branch access; they can edit workflows
that use your Konnect token. Fork and dependency-bot pull requests are
skipped because they don’t receive repository secrets.
The version comes from the Kong Developer site’s shared release data when the page
is built. Your copied workflow stays pinned; update kongctl-version
when you’re ready to upgrade.