Skip to content

Commit

Permalink
chore: ensure PR workflows can't write to GHCR (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd committed Feb 21, 2024
1 parent ce4f799 commit a41e96c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
name: E2E Tests
name: Test GHCR Write
on:
pull_request:
paths-ignore:
- "**.md"
- "**.jpg"
- "**.png"
- "**.gif"
- "**.svg"
- "adr/**"
- "docs/**"
- "CODEOWNERS"
- "goreleaser.yml"
schedule:
- cron: '0 7 * * *' ## Every day at 0700 UTC

workflow_dispatch: ## Give us the ability to run this manually

permissions:
contents: read

# Abort prior jobs in the same workflow / PR
concurrency:
group: e2e-k3d-${{ github.ref }}
group: e2e-ghcr-write-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -47,7 +40,7 @@ jobs:

- name: Run e2e tests
run: |
make test-e2e
make test-e2e-ghcr
env:
GITHUB_TOKEN: secrets.GITHUB_TOKEN

Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/test-e2e-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: E2E Tests
on:
pull_request:
paths-ignore:
- "**.md"
- "**.jpg"
- "**.png"
- "**.gif"
- "**.svg"
- "adr/**"
- "docs/**"
- "CODEOWNERS"
- "goreleaser.yml"

permissions:
contents: read

# Abort prior jobs in the same workflow / PR
concurrency:
group: e2e-k3d-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup golang
uses: ./.github/actions/golang

- name: Build UDS-CLI binary
run: make build-cli-linux-amd ARCH=amd64

- name: Setup K3d
uses: ./.github/actions/k3d

- name: Run e2e tests
run: |
make test-e2e-no-ghcr-write
- name: Save logs
if: always()
uses: ./.github/actions/save-logs
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ test-unit: ## Run Unit Tests
test-e2e: ## Run End to End (e2e) tests
cd src/test/e2e && go test -failfast -v -timeout 30m

test-e2e-no-ghcr: ## Run End to End (e2e) tests without GHCR
test-e2e-ghcr: ## Run End to End (e2e) tests with GHCR (contains writes)
cd src/test/e2e && go test -failfast -v -timeout 30m -run ".*GHCR.*"

test-e2e-no-ghcr-write: ## Run End to End (e2e) tests without GHCR
cd src/test/e2e && go test -failfast -v -timeout 30m -skip ".*GHCR.*"

test-e2e-only-tasks: ## Run End to End (e2e) tests for task runner only
test-e2e-runner: ## Run End to End (e2e) tests for task runner only
cd src/test/e2e && go test -failfast -v -timeout 30m -run TestTaskRunner

schema: ## Update JSON schema for uds-bundle.yaml
Expand Down
4 changes: 4 additions & 0 deletions src/test/e2e/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func TestBundle(t *testing.T) {
//Test create using custom tmpDir
runCmd(t, "create "+bundleDir+" --tmpdir ./customtmp --confirm --insecure")

// remove customtmp folder if it exists
err := os.RemoveAll("./customtmp")
require.NoError(t, err)

}

func TestPackagesFlag(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions src/test/e2e/ghcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (

// NOTE: These tests need to have the string "GHCR" in their names
// to ensure they are not run by the test-e2e-no-ghcr make target
// Also, these tests are run nightly and on releases, not on PRs

func TestBundleDeployFromOCIFromGHCR(t *testing.T) {
func TestBundleCreateAndPublishGHCR(t *testing.T) {
deployZarfInit(t)

bundleName := "ghcr-test"
Expand Down Expand Up @@ -51,7 +52,7 @@ func TestBundleDeployFromOCIFromGHCR(t *testing.T) {
}

// test the create -o path
func TestBundleCreateAndDeployGHCR(t *testing.T) {
func TestBundleCreateRemoteAndDeployGHCR(t *testing.T) {
deployZarfInit(t)

bundleDir := "src/test/bundles/06-ghcr"
Expand Down

0 comments on commit a41e96c

Please sign in to comment.