diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock index 3afc96c8b..54e19dc4a 100644 --- a/.github/workflows/actions.lock +++ b/.github/workflows/actions.lock @@ -35,7 +35,7 @@ workflows: '.github/workflows/test.yml': - 'actions/checkout@v4.4.0' - 'actions/setup-go@v6.5.0' - - 'docker/login-action@v3.7.0' + - 'docker/login-action@v4.7.0' '.github/workflows/vuln-remediation.yml': [] dependencies: 'actions/checkout@v4.4.0': @@ -68,9 +68,9 @@ dependencies: commit: 'sha1-7474bc4690e29a8392af63c5b98e7449536d5c3a' owner_id: 57468012 repo_id: 220391287 - 'docker/login-action@v3.7.0': - ref: 'v3.7.0' - commit: 'sha1-c94ce9fb468520275223c153574b00df6fe4bcc9' + 'docker/login-action@v4.7.0': + ref: 'v4.7.0' + commit: 'sha1-81c6f93d4bc991e510b342a00b419b3bb4efc5c6' owner_id: 5429470 repo_id: 287743349 'docker/setup-buildx-action@v3.12.0': diff --git a/.github/workflows/test-command.yml b/.github/workflows/test-command.yml index fb2802da6..ffe3fd87e 100644 --- a/.github/workflows/test-command.yml +++ b/.github/workflows/test-command.yml @@ -56,15 +56,21 @@ jobs: run: | set -euo pipefail gh api "repos/$REPO/pulls/$PR_NUMBER" \ - --jq '[.state, .base.ref, .head.repo.full_name, .head.sha] | @tsv' > "$RUNNER_TEMP/pr.tsv" - read -r state base_repo head_repo head_sha < "$RUNNER_TEMP/pr.tsv" + --jq '[.state, .base.ref, .head.repo.full_name, .head.sha, .head.ref] | @tsv' > "$RUNNER_TEMP/pr.tsv" + read -r state base_repo head_repo head_sha head_ref < "$RUNNER_TEMP/pr.tsv" if [ "$state" != "open" ] || [ "$base_repo" != "main" ] || [ -z "$head_repo" ]; then echo "::error::only open pull requests targeting main can be tested" exit 1 fi + if [ "$head_repo" != "$REPO" ]; then + gh api "repos/$REPO/issues/$PR_NUMBER/comments" \ + --field body="Full CI runs from branches in this repository only. A maintainer can review the changes and push them to a branch here to run CI." + exit 1 + fi { echo "head_repo=$head_repo" echo "head_sha=$head_sha" + echo "head_ref=$head_ref" } >> "$GITHUB_OUTPUT" - name: Reject commits pushed after the command @@ -93,23 +99,6 @@ jobs: exit 1 fi - - name: Reject dependency changes - if: steps.command.outputs.run == 'true' && steps.pr.outputs.head_repo != github.repository - env: - GH_TOKEN: ${{ github.token }} - REPO: ${{ github.repository }} - PR_NUMBER: ${{ github.event.issue.number }} - run: | - set -euo pipefail - dependency_files="$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" \ - --jq '.[] | select(.filename == "go.mod" or .filename == "go.sum") | .filename')" - if [ -n "$dependency_files" ]; then - gh api "repos/$REPO/issues/$PR_NUMBER/comments" \ - --field body="Tests were not dispatched because public contributions cannot change go.mod or go.sum." - echo "::error::public contribution changes dependency files: $dependency_files" - exit 1 - fi - - name: Dispatch tests if: steps.command.outputs.run == 'true' env: @@ -118,6 +107,7 @@ jobs: PR_NUMBER: ${{ github.event.issue.number }} HEAD_REPO: ${{ steps.pr.outputs.head_repo }} HEAD_SHA: ${{ steps.pr.outputs.head_sha }} + HEAD_REF: ${{ steps.pr.outputs.head_ref }} run: | set -euo pipefail current_head_sha="$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha')" @@ -130,7 +120,7 @@ jobs: gh workflow run test.yml \ --repo "$REPO" \ - --ref main \ + --ref "$HEAD_REF" \ --field pr_head_repo="$HEAD_REPO" \ --field pr_head_sha="$HEAD_SHA" \ --field pr_number="$PR_NUMBER" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2a57fc18..4c309f938 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ on: workflow_dispatch: inputs: pr_head_repo: - description: "Fork repository containing the PR commit" + description: "Repository containing the PR branch (must be this repository)" required: false type: string pr_head_sha: @@ -28,25 +28,25 @@ concurrency: group: test-${{ (github.event_name == 'push' && github.ref != 'refs/heads/main') && github.ref || github.run_id }} cancel-in-progress: ${{ github.event_name == 'push' && github.ref != 'refs/heads/main' }} -# A slash-command dispatch supplies a fork repository and immutable commit SHA. -# Normal push runs use the upstream repository and pushed ref. -env: - TEST_PR_HEAD_REPO: ${{ inputs.pr_head_repo || github.repository }} - TEST_SOURCE_REPO: ${{ inputs.pr_head_repo || github.repository }} - TEST_SOURCE_REF: ${{ inputs.pr_head_sha || github.ref }} - permissions: contents: read +env: + DOCKERHUB_OIDC_CONNECTIONID: e87832ce-a4e3-4386-8b17-44a6085109f2 + DOCKERHUB_OIDC_EXPIREIN: '3600' + jobs: test: + # Test the commit selected by GitHub, not a dispatch-supplied checkout. + if: ${{ github.repository == 'kernel/hypeman' && (!inputs.pr_head_repo || inputs.pr_head_repo == github.repository) && (!inputs.pr_head_sha || inputs.pr_head_sha == github.sha) }} runs-on: [self-hosted, linux, x64, kvm] + permissions: + contents: read + id-token: write steps: - uses: actions/checkout@v4.4.0 with: clean: false - repository: ${{ env.TEST_SOURCE_REPO }} - ref: ${{ env.TEST_SOURCE_REF }} persist-credentials: false - name: Clean workspace (preserve binary caches) @@ -166,13 +166,13 @@ jobs: done exit 1 - # Slash-command runs are maintainer-approved and need authenticated pulls - # for images that are not covered by the prewarm cache. - - name: Login to Docker Hub - uses: docker/login-action@v3.7.0 + - name: Create isolated Docker config + run: echo "DOCKER_CONFIG=$(mktemp -d "$RUNNER_TEMP/docker-config.XXXXXX")" >> "$GITHUB_ENV" + + - name: Login to Docker Hub with OIDC + uses: docker/login-action@v4.7.0 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + username: onkernel - name: Generate OpenAPI code run: make oapi-generate @@ -220,7 +220,6 @@ jobs: - name: Prewarm test cache env: - DOCKER_CONFIG: /home/debianuser/.docker GITHUB_TOKEN: ${{ github.token }} HYPEMAN_TEST_REGISTRY: 127.0.0.1:5001 run: | @@ -260,13 +259,11 @@ jobs: env: GO_TEST_TIMEOUT: 600s GITHUB_TOKEN: ${{ github.token }} - # Docker auth for tests running as root (sudo) - DOCKER_CONFIG: /home/debianuser/.docker # TLS/ACME testing (optional - tests will skip if not configured) - ACME_EMAIL: ${{ env.TEST_PR_HEAD_REPO == github.repository && secrets.ACME_EMAIL || '' }} + ACME_EMAIL: ${{ secrets.ACME_EMAIL }} ACME_DNS_PROVIDER: "cloudflare" ACME_CA: "https://acme-staging-v02.api.letsencrypt.org/directory" - CLOUDFLARE_API_TOKEN: ${{ env.TEST_PR_HEAD_REPO == github.repository && secrets.CLOUDFLARE_API_TOKEN || '' }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} TLS_TEST_DOMAIN: "test.hypeman-development.com" TLS_ALLOWED_DOMAINS: '*.hypeman-development.com' HYPEMAN_TEST_PREWARM_STRICT: "1" @@ -283,7 +280,7 @@ jobs: make test TEST_TIMEOUT=20m report-pr-test: - if: ${{ always() && github.event_name == 'workflow_dispatch' && inputs.pr_number != '' }} + if: ${{ always() && github.event_name == 'workflow_dispatch' && inputs.pr_number != '' && (needs.test.result == 'success' || needs.test.result == 'failure') }} needs: test runs-on: ubuntu-latest permissions: @@ -323,7 +320,11 @@ jobs: --field target_url="$GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID" test-darwin: + if: ${{ github.repository == 'kernel/hypeman' && (!inputs.pr_head_repo || inputs.pr_head_repo == github.repository) && (!inputs.pr_head_sha || inputs.pr_head_sha == github.sha) }} runs-on: [self-hosted, macos, arm64] + permissions: + contents: read + id-token: write concurrency: group: macos-ci-test-${{ inputs.pr_head_sha || github.ref }} cancel-in-progress: true @@ -332,8 +333,6 @@ jobs: steps: - uses: actions/checkout@v4.4.0 with: - repository: ${{ env.TEST_SOURCE_REPO }} - ref: ${{ env.TEST_SOURCE_REF }} persist-credentials: false - uses: actions/setup-go@v6.5.0 with: @@ -368,11 +367,10 @@ jobs: done docker info - - name: Login to Docker Hub - uses: docker/login-action@v3.7.0 + - name: Login to Docker Hub with OIDC + uses: docker/login-action@v4.7.0 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + username: onkernel - name: Install dependencies run: | brew list e2fsprogs &>/dev/null || brew install e2fsprogs @@ -440,14 +438,15 @@ jobs: e2e-install: runs-on: [self-hosted, macos, arm64] needs: test-darwin + permissions: + contents: read + id-token: write concurrency: group: macos-ci-e2e-${{ inputs.pr_head_sha || github.ref }} cancel-in-progress: true steps: - uses: actions/checkout@v4.4.0 with: - repository: ${{ env.TEST_SOURCE_REPO }} - ref: ${{ env.TEST_SOURCE_REF }} persist-credentials: false - uses: actions/setup-go@v6.5.0 with: @@ -473,11 +472,10 @@ jobs: # Self-hosted runners retain Docker layers across jobs. Prune only # what is stale, and fall back to a full prune when host disk is low. bash scripts/docker-ci-cleanup.sh - - name: Login to Docker Hub - uses: docker/login-action@v3.7.0 + - name: Login to Docker Hub with OIDC + uses: docker/login-action@v4.7.0 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + username: onkernel - name: Build E2E install artifacts env: GITHUB_TOKEN: ${{ github.token }}