-
Notifications
You must be signed in to change notification settings - Fork 13
183 lines (171 loc) · 6.68 KB
/
Copy pathbuild-test.yml
File metadata and controls
183 lines (171 loc) · 6.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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 * * *"
workflow_dispatch:
inputs:
omicron_version:
description: 'Git object to use for Omicron (commit SHA, tag, branch etc.). If not specified, the VERSION_OMICRON from oxide.go is used.'
testrail-upload:
description: 'Upload test results to TestRail'
type: boolean
required: false
default: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/acctest-omicron-dev
jobs:
build-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tf-binary:
- terraform
- tofu
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v4
if: matrix.tf-binary == 'terraform'
with:
terraform_wrapper: false
- uses: opentofu/setup-opentofu@v2
if: matrix.tf-binary == 'tofu'
with:
tofu_wrapper: false
- uses: astral-sh/setup-uv@v7
with:
# We don't have any Python dependencies to cache.
enable-cache: false
- name: set env
run: |
echo "CHECKPOINT_DISABLE=1" >> "$GITHUB_ENV"
echo "TF_ACC_TERRAFORM_PATH=$(which ${{ matrix.tf-binary }})" >> "$GITHUB_ENV"
- name: build
run: make build
- name: test
run: |
mkdir ./unittest
make test
env:
CHECKPOINT_DISABLE: "1"
TEST_GOTESTSUM_ARGS: "--rerun-fails-report=./unittest/unit-test-rerun.txt --junitfile=./unittest/unit-tests.xml"
# Explicitly skip TestAcc* test to avoid polluting TestRail results
# with unnecessary Skipped results.
TEST_NAME: "^Test($|[^A]|A$|A[^c]|Ac$|Ac[^c])"
TF_ACC_PROVIDER_NAMESPACE: oxidecomputer
- name: lint
if: matrix.tf-binary == 'terraform' # Linting tools require Terraform to be installed.
run: make lint
- name: upload test results to TestRail
if: ${{ always() && inputs.testrail-upload }}
continue-on-error: true
env:
TR_CLI_HOST: ${{ secrets.TESTRAIL_HOST }}
TR_CLI_USERNAME: ${{ secrets.TESTRAIL_USERNAME }}
TR_CLI_KEY: ${{ secrets.TESTRAIL_API_KEY }}
TR_CLI_PROJECT: ${{ secrets.TESTRAIL_PROJECT }}
run: |
uvx trcli \
--yes `# Auto-create new test cases.` \
parse_junit \
--file './unittest/unit-tests.xml' \
--title 'Unit Tests (${{ matrix.tf-binary }}) - ${{ github.run_id }} - ${{ job.check_run_id }}' \
--run-description 'GitHub workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ job.check_run_id }}' \
--update-existing-cases 'yes' \
--case-matcher 'auto' \
--close-run
# 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@v7
- id: version
env:
GH_TOKEN: ${{ github.token }}
IS_SCHEDULE: ${{ github.event_name == 'schedule' }}
OMICRON_VERSION: ${{ inputs.omicron_version }}
run: |
if [[ "${IS_SCHEDULE}" == "true" ]]; then
OMICRON_VERSION='main'
fi
OMICRON_SHA=$(./acctest/omicron-version.sh "${OMICRON_VERSION}")
echo "**Omicron version:** \`${OMICRON_VERSION:--}\`" >> $GITHUB_STEP_SUMMARY
echo "**Omicron SHA:** [\`${OMICRON_SHA}\`](https://github.com/oxidecomputer/omicron/commit/${OMICRON_SHA})" >> $GITHUB_STEP_SUMMARY
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@v7
- 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@v4
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@v4
- name: Build and push
if: steps.check.outputs.exists == 'false'
uses: docker/build-push-action@v7
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 }}
testrail-upload: ${{ inputs.testrail-upload }}
secrets:
testrail-host: ${{ secrets.TESTRAIL_HOST }}
testrail-username: ${{ secrets.TESTRAIL_USERNAME }}
testrail-api-key: ${{ secrets.TESTRAIL_API_KEY }}
testrail-project: ${{ secrets.TESTRAIL_PROJECT }}