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
99 changes: 98 additions & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,107 @@ jobs:
exit 1
fi

image:
name: Publish container image (pre-release)
runs-on: ubuntu-latest
needs: verify
permissions:
contents: read
packages: write
id-token: write
attestations: write
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
with:
platforms: linux/amd64,linux/arm64

- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1

- uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# only the pre-release's own version; never latest or a floating major
- id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ghcr.io/${{ github.repository }}
tags: type=raw,value=${{ inputs.version }}

- id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Install cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2

- name: Sign image
run: cosign sign --yes "ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}"

- name: Attest image provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true

chart:
name: Publish Helm chart (pre-release)
runs-on: ubuntu-latest
needs: image
permissions:
contents: read
packages: write
id-token: write
attestations: write
env:
VERSION: ${{ inputs.version }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1

- name: Helm registry login
run: echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u "${{ github.actor }}" --password-stdin

- name: Package and push chart
id: push
run: |
helm package charts/prow-github-app --version "$VERSION" --app-version "$VERSION" --destination .
out=$(helm push "prow-github-app-${VERSION}.tgz" "oci://ghcr.io/${{ github.repository }}/charts" 2>&1)
echo "$out"
echo "digest=$(echo "$out" | grep -oE 'sha256:[a-f0-9]{64}')" >> "$GITHUB_OUTPUT"

- name: Install cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2

- name: Sign chart
run: cosign sign --yes "ghcr.io/${{ github.repository }}/charts/prow-github-app@${{ steps.push.outputs.digest }}"

- name: Attest chart provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ghcr.io/${{ github.repository }}/charts/prow-github-app
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

github-release:
name: Create Pre-Release
runs-on: ubuntu-latest
needs: verify
needs: [verify, image, chart]
permissions:
contents: write
id-token: write # For cosign keyless signing
Expand Down
121 changes: 120 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,114 @@ jobs:
exit 1
fi

image:
name: Publish container image
runs-on: ubuntu-latest
needs: verify
permissions:
contents: read
packages: write
id-token: write # cosign keyless signing
attestations: write # GitHub artifact attestations
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
with:
platforms: linux/amd64,linux/arm64

- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1

- uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# v3.2.0 → 3.2.0, 3.2, 3 and latest; a pre-release (anything with a '-') gets only its own version
- id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}},enable=${{ !contains(github.ref_name, '-') }}
type=semver,pattern={{major}},enable=${{ !contains(github.ref_name, '-') }}
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }}

- id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Install cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2

# the multi-arch index digest, not a per-platform one
- name: Sign image
run: cosign sign --yes "ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}"

- name: Attest image provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true

chart:
name: Publish Helm chart
runs-on: ubuntu-latest
needs: image
permissions:
contents: read
packages: write
id-token: write
attestations: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1

- name: Extract version from tag
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"

- name: Helm registry login
run: echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u "${{ github.actor }}" --password-stdin

# the chart's version and appVersion are the release; the image tag defaults to appVersion
- name: Package and push chart
id: push
run: |
helm package charts/prow-github-app --version "$VERSION" --app-version "$VERSION" --destination .
out=$(helm push "prow-github-app-${VERSION}.tgz" "oci://ghcr.io/${{ github.repository }}/charts" 2>&1)
echo "$out"
echo "digest=$(echo "$out" | grep -oE 'sha256:[a-f0-9]{64}')" >> "$GITHUB_OUTPUT"

- name: Install cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2

- name: Sign chart
run: cosign sign --yes "ghcr.io/${{ github.repository }}/charts/prow-github-app@${{ steps.push.outputs.digest }}"

- name: Attest chart provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ghcr.io/${{ github.repository }}/charts/prow-github-app
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: verify
needs: [verify, image, chart]
permissions:
contents: write
id-token: write # For cosign keyless signing
Expand Down Expand Up @@ -116,6 +220,21 @@ jobs:
- uses: ${{ github.repository }}@${{ github.ref_name }}
```

## GitHub App (beta)

Container image and Helm chart for [running Prow as a GitHub App](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/docs/github-app.md):
```bash
docker pull ghcr.io/${{ github.repository }}@${{ needs.image.outputs.digest }}
helm install prow oci://ghcr.io/${{ github.repository }}/charts/prow-github-app --version ${{ env.VERSION }}
```
Both are signed with cosign (keyless) and carry SLSA provenance:
```bash
cosign verify ghcr.io/${{ github.repository }}:${{ env.VERSION }} \
--certificate-identity-regexp="https://github.com/${{ github.repository }}" \
--certificate-oidc-issuer="https://token.actions.githubusercontent.com"
gh attestation verify oci://ghcr.io/${{ github.repository }}:${{ env.VERSION }} --repo ${{ github.repository }}
```

## SBOM and provenance

An SPDX 2.3 SBOM of the runtime dependencies, generated with
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,48 @@ jobs:
path: coverage-e2e/
retention-days: 14
if-no-files-found: ignore

# the Helm chart: lint on every run, and install the two topologies into a kind cluster against an
# image built from this very commit (loaded into kind, never pushed)
chart:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1
- uses: helm/chart-testing-action@720270857a28afd41e2426521a7801db09e9b510 # v2.9.0
- name: Lint
run: ct lint --config ct.yaml --all
- name: Unit tests
run: |
helm plugin install https://github.com/helm-unittest/helm-unittest --version 1.2.1 --verify=false
helm unittest charts/prow-github-app
- uses: helm/kind-action@1544676c07bb3570fcb70166beaa07c4528fd4aa # v1.15.1
- name: Build the image from this commit and load it into kind
run: |
docker build -t prow-github-app:ci .
kind load docker-image prow-github-app:ci --name chart-testing
- name: Install (one replica)
run: |
helm install single charts/prow-github-app -f charts/prow-github-app/ci/single-values.yaml \
--set image.repository=prow-github-app --set image.tag=ci --wait --timeout 120s
kubectl rollout status deploy/single-prow-github-app --timeout=60s
kubectl run curl --rm -i --restart=Never --image=curlimages/curl:8.11.1 -- -sf http://single-prow-github-app:8080/readyz
- name: Install (two replicas, external Redis)
run: |
kubectl apply -f charts/prow-github-app/ci/redis.yaml
kubectl rollout status deploy/ci-redis --timeout=60s
helm install ha charts/prow-github-app -f charts/prow-github-app/ci/ha-external-redis-values.yaml \
--set image.repository=prow-github-app --set image.tag=ci --wait --timeout 120s
kubectl rollout status deploy/ha-prow-github-app --timeout=60s
test "$(kubectl get deploy ha-prow-github-app -o jsonpath='{.status.readyReplicas}')" = 2
kubectl get pdb ha-prow-github-app
kubectl logs deploy/ha-prow-github-app --all-containers | grep -q '"redis: connected"'
- name: A signed ping reaches the HA service
run: |
body='{"zen":"x","hook_id":1}'
sig="sha256=$(printf '%s' "$body" | openssl dgst -sha256 -hmac ci-secret | sed 's/.* //')"
code=$(kubectl run curl --rm -i --restart=Never --image=curlimages/curl:8.11.1 -- -s -o /dev/null -w '%{http_code}' \
-X POST http://ha-prow-github-app:8080/webhook -H 'x-github-delivery: ci-1' -H 'x-github-event: ping' -H "x-hub-signature-256: $sig" -d "$body" | head -c 3)
test "$code" = 200
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ FROM node:24-slim AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --ignore-scripts
COPY tsconfig.json tsconfig.core.json ./
COPY tsconfig.json ./
COPY src ./src
RUN npm run build && npm run pack:server
# the server bundle only; the action and the Worker have their own builds and type checks in CI
RUN npx tsc --noEmit && npm run pack:server

FROM node:24-slim
LABEL org.opencontainers.image.source="https://github.com/cncf/prow-github-actions" \
org.opencontainers.image.description="Prow-style chat-ops for GitHub, as a GitHub App" \
org.opencontainers.image.licenses="MIT"
ENV NODE_ENV=production PORT=8080
USER node
WORKDIR /app
COPY --from=build /app/dist-server ./dist-server
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s CMD ["node", "-e", "fetch('http://127.0.0.1:'+(process.env.PORT||8080)+'/healthz').then(r=>process.exit(r.ok?0:1),()=>process.exit(1))"]
CMD ["node", "dist-server/index.js"]
22 changes: 21 additions & 1 deletion __tests__/docsYamlExamples.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readdirSync, readFileSync, statSync } from 'node:fs'
import * as path from 'node:path'
import Ajv from 'ajv/dist/2020'
import * as yaml from 'js-yaml'
import { describe, expect, it } from 'vitest'

Expand Down Expand Up @@ -89,7 +90,7 @@ const sectionFields: Record<string, string[]> = {
const ownersKeys = ['approvers', 'reviewers', 'emeritus_approvers', 'emeritus_reviewers', 'filters', 'labels', 'options']
const workflowKeys = ['on', 'jobs', 'permissions', 'concurrency', 'steps', 'runs-on']

type Kind = 'workflow' | 'owners' | 'prow'
type Kind = 'workflow' | 'owners' | 'prow' | 'helm'

/** a job's `steps:` list quoted on its own, e.g. `- uses: cncf/prow-github-actions@v3` */
function isStepList(loaded: unknown): boolean {
Expand All @@ -110,10 +111,24 @@ function isOwners(block: Block): boolean {
return /OWNERS|`approvers`|`reviewers`/.test(block.intro) || (comment.startsWith('#') && comment.includes('OWNERS'))
}

/** a Helm values example for charts/prow-github-app: its keys are the chart's top-level values */
const chartDir = path.join(root, 'charts', 'prow-github-app')
const chartDefaults = yaml.load(readFileSync(path.join(chartDir, 'values.yaml'), 'utf8')) as Record<string, unknown>
const chartSchema = JSON.parse(readFileSync(path.join(chartDir, 'values.schema.json'), 'utf8')) as object
const validateValues = new Ajv({ allErrors: true, strict: false }).compile(chartSchema)

function isHelmValues(loaded: Record<string, unknown>): boolean {
const keys = Object.keys(loaded)
return keys.length > 0 && keys.every(key => key in chartDefaults)
}

function classify(block: Block, loaded: unknown): Kind {
if (isStepList(loaded) || !isMapping(loaded)) {
return 'workflow'
}
if (isHelmValues(loaded)) {
return 'helm'
}
const keys = Object.keys(loaded)
if (keys.some(key => workflowKeys.includes(key))) {
return 'workflow'
Expand Down Expand Up @@ -144,6 +159,11 @@ describe('every fenced yaml block in the guides', () => {
const doc = isMapping(loaded) ? loaded : {}
const kind = classify(block, loaded)

it.runIf(kind === 'helm')('is a values fragment the chart schema accepts on top of the defaults', () => {
const merged = { ...chartDefaults, ...doc, github: { ...(chartDefaults.github as object), appId: '1', privateKey: 'k', webhookSecret: 's', ...((doc.github as object | undefined) ?? {}) } }
expect(validateValues(merged), `${at}: ${JSON.stringify(validateValues.errors)}`).toBe(true)
})

it.runIf(kind === 'owners')('parses as an OWNERS file naming somebody, with no key parseOwners would skip', () => {
for (const key of Object.keys(doc)) {
expect(ownersKeys, `${at}: unknown OWNERS key '${key}'`).toContain(key)
Expand Down
Loading
Loading