Skip to content

Commit

Permalink
Replace Makefile with Earthfile
Browse files Browse the repository at this point in the history
Signed-off-by: Nic Cope <nicc@rk0n.org>
  • Loading branch information
negz committed May 17, 2024
1 parent efd0a5e commit a4499b1
Show file tree
Hide file tree
Showing 2 changed files with 289 additions and 206 deletions.
263 changes: 57 additions & 206 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,31 @@ jobs:
with:
submodules: true

- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5
- name: Setup Earthly
uses: earthly/actions-setup@v1
with:
go-version: ${{ env.GO_VERSION }}
github-token: ${{ secrets.GITHUB_TOKEN }}
version: "0.8.9"

- name: Find the Go Build Cache
id: go
run: echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT

- name: Cache the Go Build Cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: ${{ steps.go.outputs.cache }}
key: ${{ runner.os }}-build-check-diff-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-check-diff-

- name: Cache Go Dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
if: env.DOCKER_USR != ''
with:
path: .work/pkg
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-
username: ${{ secrets.DOCKER_USR }}
password: ${{ secrets.DOCKER_PSW }}

- name: Download Go Modules
run: make modules.download modules.check
- name: Generate Files
run: earthly +generate

- name: Check Diff
run: make check-diff
- name: Count Changed Files
id: changed_files
run: echo "count=$(git status --porcelain | wc -l)" >> $GITHUB_OUTPUT

- name: Fail if Files Changed
if: steps.changed_files.outputs.count != 0
uses: actions/github-script
with:
script: core.setFailed('Found changed files after running earthly +generate.'')

detect-noop:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -90,35 +87,13 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- name: Find the Go Build Cache
id: go
run: echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT

- name: Cache the Go Build Cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: ${{ steps.go.outputs.cache }}
key: ${{ runner.os }}-build-lint-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-lint-

- name: Cache Go Dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: .work/pkg
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-

- name: Download Go Modules
run: make modules.download modules.check

# We could run 'make lint' to ensure our desired Go version, but we prefer
# this action because it leaves 'annotations' (i.e. it comments on PRs to
# point out linter violations).
# We could run 'earthly _lint' to ensure our desired Go version, but we
# prefer this action because it leaves 'annotations' (i.e. it comments on
# PRs to point out linter violations).
- name: Lint
uses: golangci/golangci-lint-action@d6238b002a20823d52840fda27e2d4891c5952dc # v4
with:
version: ${{ env.GOLANGCI_VERSION }}
skip-cache: true # We do our own caching.

codeql:
runs-on: ubuntu-22.04
Expand All @@ -145,7 +120,7 @@ jobs:
with:
path: ${{ steps.go.outputs.cache }}
key: ${{ runner.os }}-build-check-diff-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-check-diff-
restore-keys: ${{ runner.os }}-build-codeql-

- name: Cache Go Dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
Expand All @@ -154,9 +129,6 @@ jobs:
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-

- name: Download Go Modules
run: make modules.download modules.check

- name: Initialize CodeQL
uses: github/codeql-action/init@b7cec7526559c32f1616476ff32d17ba4c59b2d6 # v3
with:
Expand Down Expand Up @@ -196,43 +168,32 @@ jobs:
with:
submodules: true

- name: Fetch History
run: git fetch --prune --unshallow

- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Find the Go Build Cache
id: go
run: echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT

- name: Cache the Go Build Cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
- name: Setup Earthly
uses: earthly/actions-setup@v1
with:
path: ${{ steps.go.outputs.cache }}
key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-unit-tests-
github-token: ${{ secrets.GITHUB_TOKEN }}
version: "0.8.9"

- name: Cache Go Dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
if: env.DOCKER_USR != ''
with:
path: .work/pkg
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-

- name: Download Go Modules
run: make modules.download modules.check
username: ${{ secrets.DOCKER_USR }}
password: ${{ secrets.DOCKER_PSW }}

- name: Run Unit Tests
run: make -j2 test
run: earthly +test

- name: Publish Unit Test Coverage
uses: codecov/codecov-action@6d798873df2b1b8e5846dba6fb86631229fbcb17 # v4
with:
flags: unittests
file: _output/tests/linux_amd64/coverage.txt
file: _output/tests/coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}

e2e-tests:
Expand All @@ -249,71 +210,27 @@ jobs:
- ssa-claims

steps:
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
platforms: all

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
with:
version: ${{ env.DOCKER_BUILDX_VERSION }}
install: true

- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
submodules: true

- name: Fetch History
run: git fetch --prune --unshallow

- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5
- name: Setup Earthly
uses: earthly/actions-setup@v1
with:
go-version: ${{ env.GO_VERSION }}

- name: Find the Go Build Cache
id: go
run: echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT
github-token: ${{ secrets.GITHUB_TOKEN }}
version: "0.8.9"

- name: Cache the Go Build Cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: ${{ steps.go.outputs.cache }}
key: ${{ runner.os }}-build-e2e-tests-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-e2e-tests-

- name: Cache Go Dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
if: env.DOCKER_USR != ''
with:
path: .work/pkg
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-pkg-
- name: Download Go Modules
run: make modules.download modules.check

- name: Build Helm Chart
run: make -j2 build
env:
# We're using docker buildx, which doesn't actually load the images it
# builds by default. Specifying --load does so.
BUILD_ARGS: "--load"
username: ${{ secrets.DOCKER_USR }}
password: ${{ secrets.DOCKER_PSW }}

- name: Run E2E Tests
run: make e2e E2E_TEST_FLAGS="-test.v -test.failfast -fail-fast --kind-logs-location ./logs-kind --test-suite ${{ matrix.test-suite }}"
run: earthly +e2e --FLAGS="-test.failfast -fail-fast --test-suite ${{ matrix.test-suite }}"

- name: Upload artifacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
if: failure()
with:
name: e2e-kind-logs-${{ matrix.test-suite }}
path: ./logs-kind
if-no-files-found: error
retention-days: 7

- name: Publish E2E Test Flakes
if: '!cancelled()'
uses: buildpulse/buildpulse-action@d0d30f53585cf16b2e01811a5a753fd47968654a # v0.11.0
Expand All @@ -330,80 +247,35 @@ jobs:
if: needs.detect-noop.outputs.noop != 'true'

steps:
- name: Cleanup Disk
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
with:
android: true
dotnet: true
haskell: true
tool-cache: true
large-packages: false
swap-storage: false

- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
platforms: all

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
with:
version: ${{ env.DOCKER_BUILDX_VERSION }}
install: true

- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
submodules: true

- name: Fetch History
run: git fetch --prune --unshallow

- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Find the Go Build Cache
id: go
run: echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT

- name: Cache the Go Build Cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
- name: Setup Earthly
uses: earthly/actions-setup@v1
with:
path: ${{ steps.go.outputs.cache }}
key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-publish-artifacts-
github-token: ${{ secrets.GITHUB_TOKEN }}
version: "0.8.9"

- name: Cache Go Dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
if: env.DOCKER_USR != ''
with:
path: .work/pkg
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-

- name: Download Go Modules
run: make modules.download modules.check
username: ${{ secrets.DOCKER_USR }}
password: ${{ secrets.DOCKER_PSW }}

- name: Build Artifacts
run: make -j2 build.all
env:
# We're using docker buildx, which doesn't actually load the images it
# builds by default. Specifying --load does so.
BUILD_ARGS: "--load"
run: earthly +multiplatform-build

- name: Publish Artifacts to GitHub
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
with:
name: output
path: _output/**

- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
if: env.DOCKER_USR != ''
with:
username: ${{ secrets.DOCKER_USR }}
password: ${{ secrets.DOCKER_PSW }}
- name: Build Image
run: earthly +multiplatform-image

- name: Login to Upbound
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
Expand All @@ -413,27 +285,6 @@ jobs:
username: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
password: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }}

- name: Publish Artifacts to S3, Marketplace, DockerHub
run: make -j2 publish BRANCH_NAME=${GITHUB_REF##*/}
if: env.AWS_USR != '' && env.DOCKER_USR != '' && env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_USR }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PSW }}
AWS_DEFAULT_REGION: us-east-1
GIT_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCS_GIT_USR: ${{ secrets.UPBOUND_BOT_GITHUB_USR }}
DOCS_GIT_PSW: ${{ secrets.UPBOUND_BOT_GITHUB_PSW }}

- name: Promote Artifacts in S3, DockerHub
if: github.ref == 'refs/heads/master' && env.AWS_USR != '' && env.DOCKER_USR != '' && env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
run: make -j2 promote
env:
BRANCH_NAME: master
CHANNEL: master
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_USR }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PSW }}
AWS_DEFAULT_REGION: us-east-1

fuzz-test:
runs-on: ubuntu-22.04
needs: detect-noop
Expand Down
Loading

0 comments on commit a4499b1

Please sign in to comment.