From 86ec19a95f7d40ad4bbba6187da525ac99ce2f95 Mon Sep 17 00:00:00 2001 From: Lennart Jern Date: Wed, 5 Jun 2024 10:38:58 +0300 Subject: [PATCH] Workflow pipeline with unit tests This adds a unit test workflow and restructures the github workflows so that we run golangci-lint and unit tests first. Only when they have succeded will the pipeline continue with e2e tests. The goal is to conserve resources and avoid running pointless jobs. The commit also removes unnecessary permissions and avoids running the jobs if the PR is a draft. Signed-off-by: Lennart Jern --- .github/workflows/e2e-fixture-test.yml | 21 ++---------- .github/workflows/e2e-test-pull.yaml | 32 ------------------- .github/workflows/e2e-test.yml | 5 +-- .github/workflows/golangci-lint.yml | 3 +- .github/workflows/pipeline.yml | 44 ++++++++++++++++++++++++++ .github/workflows/unit.yml | 25 +++++++++++++++ 6 files changed, 74 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/e2e-test-pull.yaml create mode 100644 .github/workflows/pipeline.yml create mode 100644 .github/workflows/unit.yml diff --git a/.github/workflows/e2e-fixture-test.yml b/.github/workflows/e2e-fixture-test.yml index 8622cfd8a0..f1b355b313 100644 --- a/.github/workflows/e2e-fixture-test.yml +++ b/.github/workflows/e2e-fixture-test.yml @@ -1,30 +1,15 @@ name: E2E Fixture Test on: - pull_request: - branches: - - 'main' - - 'release-*' - paths-ignore: - - '**/*.md' - - 'docs/**' - - '.gitignore' - - 'hack/*.sh' - - 'LICENSE' - - 'SECURITY_CONTACTS' - - 'DCO' - - 'OWNERS' + workflow_call: permissions: {} jobs: test: - name: e2e test + name: E2E fixture test runs-on: ubuntu-latest - permissions: - contents: read - steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 @@ -52,7 +37,7 @@ jobs: - name: Upload artifacts uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 with: - name: artifacts.tar.gz + name: artifacts-fixture.tar.gz path: test/e2e/_artifacts if-no-files-found: error overwrite: false diff --git a/.github/workflows/e2e-test-pull.yaml b/.github/workflows/e2e-test-pull.yaml deleted file mode 100644 index 81760b4fbd..0000000000 --- a/.github/workflows/e2e-test-pull.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: E2E Test - -on: - pull_request: - branches: - - 'main' - - 'release-*' - paths-ignore: - - '**/*.md' - - 'docs/**' - - '.gitignore' - - 'hack/*.sh' - - 'LICENSE' - - 'SECURITY_CONTACTS' - - 'DCO' - - 'OWNERS' - -permissions: {} - -jobs: - e2e-test: - strategy: - fail-fast: false - matrix: - bmc-protocol: - - redfish-virtualmedia - - ipmi - uses: ./.github/workflows/e2e-test.yml - with: - bmc-protocol: ${{ matrix.bmc-protocol }} - permissions: - contents: read diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index ddbc754dcb..b24457ec98 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -20,12 +20,9 @@ permissions: {} jobs: test: - name: e2e test + name: E2E test runs-on: ${{ inputs.runner }} - permissions: - contents: read - steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 with: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index baa2cf6025..02ab30740b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,8 +1,7 @@ name: golangci-lint on: - pull_request: - types: [opened, edited, synchronize, reopened] + workflow_call: # Remove all permissions from GITHUB_TOKEN except metadata. permissions: {} diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000000..b67b5bba57 --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,44 @@ +name: E2E Test pipeline + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + branches: + - 'main' + - 'release-*' + paths-ignore: + - '**/*.md' + - 'docs/**' + - '.gitignore' + - 'LICENSE' + - 'SECURITY_CONTACTS' + - 'DCO' + - 'OWNERS' + +permissions: {} + +jobs: + golangci-lint: + if: github.event.pull_request.draft == false + uses: ./.github/workflows/golangci-lint.yml + + unit: + if: github.event.pull_request.draft == false + uses: ./.github/workflows/unit.yml + + e2e-fixture-test: + needs: [golangci-lint, unit] + uses: ./.github/workflows/e2e-fixture-test.yml + + e2e-test: + needs: [golangci-lint, unit] + strategy: + # Avoid wasting CI resources + fail-fast: true + matrix: + bmc-protocol: + - redfish-virtualmedia + - ipmi + uses: ./.github/workflows/e2e-test.yml + with: + bmc-protocol: ${{ matrix.bmc-protocol }} diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml new file mode 100644 index 0000000000..734db71f2e --- /dev/null +++ b/.github/workflows/unit.yml @@ -0,0 +1,25 @@ +name: unit + +on: + workflow_call: + +# Remove all permissions from GITHUB_TOKEN except metadata. +permissions: {} + +jobs: + golangci: + name: unit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Calculate go version + id: vars + run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT + - name: Set up Go + uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 + with: + go-version: ${{ steps.vars.outputs.go_version }} + - name: Run unit tests + run: make -e unit-cover + env: + TEST_FLAGS: "-v"