Skip to content
Merged
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
23 changes: 22 additions & 1 deletion .github/workflows/nextjs-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ on:
default: .release-please-manifest.json
type: string
secrets:
KOPEXA_OPERATOR_PRIVATE_KEY:
description: Private key of the Kopexa Operator app; preferred over the legacy tokens below
required: false
RELEASE_PLEASE_TOKEN:
description: Deprecated; use KOPEXA_OPERATOR_PRIVATE_KEY
required: false
GITOPS_TOKEN:
description: Deprecated; use KOPEXA_OPERATOR_PRIVATE_KEY
required: false
permissions:
contents: write
Expand All @@ -48,11 +53,25 @@ jobs:
created: ${{ steps.release.outputs.release_created }}
tag: ${{ steps.release.outputs.tag_name }}
staging: ${{ steps.gate.outputs.staging }}
env:
# Only a boolean, so the key itself never lands in the job environment.
USE_KOPEXA_OPERATOR: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY != '' && vars.KOPEXA_OPERATOR_CLIENT_ID != '' }}
steps:
# Release PRs opened with GITHUB_TOKEN start no PR workflows, so they would
# carry no required checks. A Kopexa Operator token does start them.
- id: operator
if: env.USE_KOPEXA_OPERATOR == 'true'
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ vars.KOPEXA_OPERATOR_CLIENT_ID }}
private-key: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
permission-issues: write
- id: release
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
with:
token: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
token: ${{ steps.operator.outputs.token || secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
config-file: ${{ inputs.release-config }}
manifest-file: ${{ inputs.release-manifest }}
- name: Exclude merged release PRs from staging (including reruns)
Expand Down Expand Up @@ -81,6 +100,7 @@ jobs:
image-tag: staging-${{ github.sha }}
application: ${{ inputs.application }}
secrets:
KOPEXA_OPERATOR_PRIVATE_KEY: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY }}
GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }}
production:
needs: release
Expand All @@ -95,4 +115,5 @@ jobs:
image-tag: ${{ needs.release.outputs.tag }}
application: ${{ inputs.application }}
secrets:
KOPEXA_OPERATOR_PRIVATE_KEY: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY }}
GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }}
18 changes: 17 additions & 1 deletion .github/workflows/nextjs-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ on:
default: linux/amd64
type: string
secrets:
KOPEXA_OPERATOR_PRIVATE_KEY:
description: Private key of the Kopexa Operator app; preferred over GITOPS_TOKEN
required: false
GITOPS_TOKEN:
description: Deprecated; use KOPEXA_OPERATOR_PRIVATE_KEY
required: false
outputs:
digest:
Expand Down Expand Up @@ -166,7 +170,19 @@ jobs:
url: ${{ vars.DEPLOYMENT_URL }}
permissions:
contents: read
env:
# Only a boolean, so the key itself never lands in the job environment.
USE_KOPEXA_OPERATOR: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY != '' && vars.KOPEXA_OPERATOR_CLIENT_ID != '' }}
steps:
- id: operator
if: vars.GITOPS_ENABLED == 'true' && env.USE_KOPEXA_OPERATOR == 'true'
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ vars.KOPEXA_OPERATOR_CLIENT_ID }}
private-key: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY }}
owner: kopexa-grc
repositories: envs
permission-actions: write
- name: Dispatch website deployment and await result
if: vars.GITOPS_ENABLED == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
Expand All @@ -177,7 +193,7 @@ jobs:
SOURCE_REF: ${{ inputs.source-ref }}
SOURCE_SHA: ${{ needs.image.outputs.source-sha }}
with:
github-token: ${{ secrets.GITOPS_TOKEN }}
github-token: ${{ steps.operator.outputs.token || secrets.GITOPS_TOKEN }}
script: |
const sourceSha = process.env.SOURCE_SHA;
const target = {owner: 'kopexa-grc', repo: 'envs'};
Expand Down
36 changes: 10 additions & 26 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ on:
branches: [main]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
issues: write
actions: write
contents: read
concurrency:
group: release-please
cancel-in-progress: false
Expand All @@ -17,27 +14,14 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- id: release
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
# Checkout only to run this repository's own action from ./github.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json
# GITHUB_TOKEN-created PRs do not trigger pull_request workflows.
# Explicit dispatch runs the same required validation on the release head.
- name: Validate the release PR
if: steps.release.outputs.prs_created == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
RELEASE_PRS: ${{ steps.release.outputs.prs }}
persist-credentials: false
# The Kopexa Operator token opens the release PR, so its pull_request
# workflows (actionlint) start on their own. No dispatch workaround needed.
- id: release
uses: ./github/release-please
with:
script: |
for (const pr of JSON.parse(process.env.RELEASE_PRS || '[]')) {
const { data } = await github.rest.pulls.get({ ...context.repo, pull_number: pr.number });
if (data.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}` ||
!data.head.ref.startsWith('release-please--')) {
throw new Error('Unexpected release PR source');
}
await github.rest.actions.createWorkflowDispatch({
...context.repo, workflow_id: 'workflow-lint.yml', ref: data.head.ref
});
}
client-id: ${{ vars.KOPEXA_OPERATOR_CLIENT_ID }}
private-key: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Call them with `steps[].uses`; your workflow owns the runner and job permissions
- [Go build](go/build/README.md)
- [Go unit tests](go/unit-test/README.md)
- [PR auto-approval](github/auto-approve/README.md)
- [Kopexa Operator app token](github/app-token/README.md): short-lived bot token instead of personal access tokens
- [Release Please](github/release-please/README.md): Release Please with a Kopexa Operator token, drop-in for the upstream step

## Reusable workflows: complete jobs

Expand Down
11 changes: 9 additions & 2 deletions docs/nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ configuration copied from the actual current deployment. Do not guess production

Secrets:

- `GITOPS_TOKEN`: GitHub App installation token or fine-grained token scoped to
- `KOPEXA_OPERATOR_PRIVATE_KEY` (organization secret) plus `KOPEXA_OPERATOR_CLIENT_ID`
(organization variable): preferred. Both workflows mint short-lived tokens of
the Kopexa Operator GitHub App, one for Release Please (Contents, Issues, Pull
requests write on the calling repo, so release PRs trigger required checks)
and one for the envs dispatch (Actions write on `kopexa-grc/envs`). Pass the
secret explicitly or with `secrets: inherit`. When it is set, the two tokens
below are ignored. See [Kopexa Operator app token](../github/app-token/README.md).
- `GITOPS_TOKEN` (deprecated, fallback): GitHub App installation token or fine-grained token scoped to
`kopexa-grc/envs` with Actions read/write. Used only to dispatch and observe
`websites.yml`; the sender no longer checks out or writes envs. Store as an
environment secret. The receiver separately needs `WEBSITE_SOURCE_TOKEN` with
source Contents/Actions read and uses its own GITHUB_TOKEN for envs commits.
- `RELEASE_PLEASE_TOKEN`: optional repository secret with Contents, Issues and Pull
- `RELEASE_PLEASE_TOKEN` (deprecated, fallback): optional repository secret with Contents, Issues and Pull
requests write. Needed if generated Release Please PRs must trigger required CI
checks. GITHUB_TOKEN fallback works for release creation and the in-workflow
production job, but its generated PRs/releases do not trigger other workflows.
Expand Down
8 changes: 4 additions & 4 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use full `vX.Y.Z` tags without a component prefix. No moving major tag is create
5. Update consumers explicitly to the release SHA, optionally with the version as
a comment, or to its full version tag. Existing SHA-pinned consumers do not move.

The workflow uses `GITHUB_TOKEN`; no new credential is needed. Because bot-created
PRs do not trigger PR workflows, it explicitly dispatches Workflow validation on
the release branch. That provides the required `actionlint` check without bypassing
branch protection. Release PRs are not automatically approved or merged.
The workflow runs this repository's own `github/release-please` action with a
Kopexa Operator token (`KOPEXA_OPERATOR_CLIENT_ID`, `KOPEXA_OPERATOR_PRIVATE_KEY`).
Release PRs opened with it trigger the required `actionlint` check like any other
PR. Release PRs are not automatically approved or merged.

The dependency upgrade uses Node.js 24 actions. Self-hosted runners must support
that runtime (at least v2.327.1; authenticated Git inside Docker with checkout v7
Expand Down
2 changes: 1 addition & 1 deletion docs/workflows/nextjs-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Ordinary commits build staging; merging a release PR builds production only.
Required inputs: `dockerfile`, `image`. Optional `application` defaults to the caller
repository name. Legacy staging/production paths are accepted but ignored.
Optional: `next-cache-target`, `release-config`, `release-manifest`.
Optional secrets: `RELEASE_PLEASE_TOKEN`, `GITOPS_TOKEN`.
Optional secrets: `KOPEXA_OPERATOR_PRIVATE_KEY` (preferred, with variable `KOPEXA_OPERATOR_CLIENT_ID`); legacy fallbacks `RELEASE_PLEASE_TOKEN`, `GITOPS_TOKEN`.
Requires write permissions for contents, pull requests, issues and packages.

Calls the image workflow at the same revision. The caller owns the `staging` and
Expand Down
2 changes: 1 addition & 1 deletion docs/workflows/nextjs-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ The sender no longer checks out envs or commits manifests.
Required inputs: environment, source-ref, dockerfile, image, image-tag.
Optional: application, next-cache-target, health-path, platforms. Legacy gitops-path
and image-alias remain accepted but are ignored. Returns the published digest.
Requires Contents read and Packages write; GITOPS_TOKEN needs envs Actions read/write.
Requires Contents read and Packages write; the envs dispatch uses a Kopexa Operator token (`KOPEXA_OPERATOR_PRIVATE_KEY` + `KOPEXA_OPERATOR_CLIENT_ID`), falling back to GITOPS_TOKEN with envs Actions read/write.

See [configuration and event contract](../nextjs.md).
76 changes: 76 additions & 0 deletions github/app-token/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Kopexa Operator app token

Mints a short-lived installation token of **Kopexa Operator**, the Kopexa CI GitHub App.
Use it wherever a workflow needs more than `GITHUB_TOKEN` can do, instead of a
personal access token:

- Pull requests opened with it (for example by Release Please) trigger the
repository's PR workflows. PRs opened with `GITHUB_TOKEN` do not.
- Cross-repository calls, for example the workflow dispatch to `envs`.

The token is valid for one hour, limited to the repositories and permissions you
request, and revoked when the job ends. It is not tied to a person.

## Configuration

| Name | Kind | Scope |
| ---- | ---- | ----- |
| `KOPEXA_OPERATOR_CLIENT_ID` | Variable | Organization kopexa-grc, selected repositories |
| `KOPEXA_OPERATOR_PRIVATE_KEY` | Secret | Organization kopexa-grc, selected repositories |

The app itself needs these repository permissions: Actions, Contents, Issues and
Pull requests read and write, Metadata read. Request only what a job needs.

## Inputs

| Name | Description | Required |
| ---- | ----------- | -------- |
| client-id | Kopexa Operator client ID | Yes |
| private-key | Kopexa Operator private key | Yes |
| owner | Owner of the target repositories, defaults to the calling owner | No |
| repositories | Repository names, defaults to the calling repository | No |
| permission-contents | `read`, `write` or empty to omit | No |
| permission-pull-requests | `read`, `write` or empty to omit | No |
| permission-issues | `read`, `write` or empty to omit | No |
| permission-actions | `read`, `write` or empty to omit | No |

Leaving every permission empty grants all permissions of the installation.

## Outputs

| Name | Description |
| ---- | ----------- |
| token | Installation token |
| app-slug | `kopexaoperator` |
| git-user-name | `kopexaoperator[bot]` |
| git-user-email | Noreply address for bot commits |

## Example: Release Please

```yaml
steps:
- id: operator
uses: kopexa-grc/github-actions/github/app-token@<sha> # vX.Y.Z
with:
client-id: ${{ vars.KOPEXA_OPERATOR_CLIENT_ID }}
private-key: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
permission-issues: write
- uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
with:
token: ${{ steps.operator.outputs.token }}
```

## Example: dispatch a workflow in another repository

```yaml
steps:
- id: operator
uses: kopexa-grc/github-actions/github/app-token@<sha> # vX.Y.Z
with:
client-id: ${{ vars.KOPEXA_OPERATOR_CLIENT_ID }}
private-key: ${{ secrets.KOPEXA_OPERATOR_PRIVATE_KEY }}
repositories: envs
permission-actions: write
```
86 changes: 86 additions & 0 deletions github/app-token/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (c) Kopexa GmbH
# SPDX-License-Identifier: BUSL-1.1

---
name: Kopexa Operator app token
description:
Mint a short-lived installation token of the Kopexa Operator GitHub App instead of
using a personal access token
author: Kopexa
inputs:
client-id:
description: Kopexa Operator client ID, usually vars.KOPEXA_OPERATOR_CLIENT_ID
required: true
private-key:
description: Kopexa Operator private key, usually secrets.KOPEXA_OPERATOR_PRIVATE_KEY
required: true
owner:
description: Owner of the target repositories
default: ${{ github.repository_owner }}
required: false
repositories:
description: |
Comma or newline separated repository names the token may access.
Defaults to the calling repository only.
default: ${{ github.event.repository.name }}
required: false
permission-contents:
description: Contents permission (read, write or empty to omit)
default: ''
required: false
permission-pull-requests:
description: Pull requests permission (read, write or empty to omit)
default: ''
required: false
permission-issues:
description: Issues permission (read, write or empty to omit)
default: ''
required: false
permission-actions:
description: Actions permission (read, write or empty to omit)
default: ''
required: false
outputs:
token:
description: Installation token, valid for one hour and revoked after the job
value: ${{ steps.token.outputs.token }}
app-slug:
description: App slug, for example kopexaoperator
value: ${{ steps.token.outputs.app-slug }}
git-user-name:
description: Commit author name of the bot, for example kopexaoperator[bot]
value: ${{ steps.identity.outputs.name }}
git-user-email:
description: Commit author email of the bot (noreply address)
value: ${{ steps.identity.outputs.email }}

runs:
using: composite
steps:
- name: Mint installation token
id: token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ inputs.client-id }}
private-key: ${{ inputs.private-key }}
owner: ${{ inputs.owner }}
repositories: ${{ inputs.repositories }}
permission-contents: ${{ inputs.permission-contents }}
permission-pull-requests: ${{ inputs.permission-pull-requests }}
permission-issues: ${{ inputs.permission-issues }}
permission-actions: ${{ inputs.permission-actions }}

- name: Resolve bot git identity
id: identity
shell: bash
env:
GH_TOKEN: ${{ steps.token.outputs.token }}
APP_SLUG: ${{ steps.token.outputs.app-slug }}
run: |
set -euo pipefail
name="${APP_SLUG}[bot]"
id="$(gh api "/users/${name}" --jq .id)"
{
echo "name=${name}"
echo "email=${id}+${name}@users.noreply.github.com"
} >> "$GITHUB_OUTPUT"
Loading
Loading