Skip to content

build & test

build & test #1512

Workflow file for this run

name: build & test
on:
push:
branches:
- main
- '[0-9].[0-9]+'
- 'rel/v*'
pull_request:
schedule:
# Cron jobs test against omicron main to catch breaking changes early.
- cron: "25 7 * * *"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/acctest-omicron-dev
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- name: build
run: make build
- name: test
run: make test
env:
CHECKPOINT_DISABLE: "1"
- name: lint
run: make lint
# Choose the appropriate omicron version for acceptance tests. For cron jobs, use `main`, since
# our goal is to detect breaking changes in omicron. Otherwise, look up the omicron version from
# the VERSION_OMICRON file in oxide.go, checking the expected version of oxide.go from go.mod.
#
# Note: we use the omicron commit hash throughout for tagging and fetching the docker image, so
# it has to be a complete SHA, not a branch name or partial SHA.
omicron-version:
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.version.outputs.sha }}
steps:
- uses: actions/checkout@v6
- id: version
env:
GH_TOKEN: ${{ github.token }}
IS_SCHEDULE: ${{ github.event_name == 'schedule' }}
run: |
if [[ "${IS_SCHEDULE}" == "true" ]]; then
OMICRON_SHA=$(./acctest/omicron-version.sh main)
else
OMICRON_SHA=$(./acctest/omicron-version.sh)
fi
echo "sha=${OMICRON_SHA}" >> $GITHUB_OUTPUT
# Build and push the acctest docker image before running acceptance tests.
# This ensures the image is available in the registry for acceptance tests to pull.
#
# Note: images are cached by omicron SHA only. If you change acctest/Dockerfile, manually delete
# the cached image from ghcr.io/oxidecomputer/terraform-provider-oxide/acctest-omicron-dev.
publish-image:
needs: omicron-version
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- name: Check if image exists
id: check
run: |
if docker manifest inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.omicron-version.outputs.sha }} > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Clean up disk space
if: steps.check.outputs.exists == 'false'
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
sudo docker builder prune -a
- name: Log in to GHCR
if: steps.check.outputs.exists == 'false'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
if: steps.check.outputs.exists == 'false'
uses: docker/setup-buildx-action@v3
- name: Build and push
if: steps.check.outputs.exists == 'false'
uses: docker/build-push-action@v6
with:
context: acctest
platforms: linux/amd64
push: true
build-args: |
OMICRON_SHA=${{ needs.omicron-version.outputs.sha }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.omicron-version.outputs.sha }}
acceptance:
needs: [omicron-version, publish-image]
uses: "./.github/workflows/acceptance-sim.yml"
with:
omicron-sha: ${{ needs.omicron-version.outputs.sha }}