CI test: Pro archives support #312
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- '**.md' | |
pull_request: | |
branches: [main] | |
jobs: | |
unit-tests: | |
runs-on: ubuntu-22.04 | |
name: Unit Tests | |
env: | |
TEST_COVERAGE_FILE: test-coverage.out | |
TEST_COVERAGE_HTML_FILE: test-coverage.html | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v3 | |
with: | |
go-version-file: 'go.mod' | |
- name: Run unit tests | |
run: go test -v -cover -coverprofile=${TEST_COVERAGE_FILE} ./... | |
- name: Convert test coverage to HTML | |
if: always() | |
continue-on-error: true | |
run: | | |
set -eu | |
if [ -f ${TEST_COVERAGE_FILE} ] | |
then | |
go tool cover -html=${TEST_COVERAGE_FILE} \ | |
-o=${TEST_COVERAGE_HTML_FILE} | |
fi | |
- name: Upload HTML test coverage | |
uses: actions/upload-artifact@v3 | |
if: always() | |
continue-on-error: true | |
with: | |
name: chisel-test-coverage.html | |
path: ./*.html | |
real-archive-tests: | |
# Do not change to newer releases as "fips" may not be available there. | |
runs-on: ubuntu-20.04 | |
name: Real Archive Tests | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v3 | |
with: | |
go-version-file: 'go.mod' | |
- name: Run real archive tests | |
env: | |
PRO_TOKEN: ${{ secrets.PRO_TOKEN }} | |
run: | | |
set -ex | |
detach() { | |
sudo pro detach --assume-yes || true | |
sudo rm -f /etc/apt/auth.conf.d/90ubuntu-advantage | |
} | |
trap detach EXIT | |
# Attach pro token and enable services | |
sudo pro attach ${PRO_TOKEN} --no-auto-enable | |
# Cannot enable fips and fips-updates at the same time. | |
# Hack: enable fips, copy the credentials and then after enabling | |
# other services, add the credentials back. | |
sudo pro enable fips --assume-yes | |
sudo cp /etc/apt/auth.conf.d/90ubuntu-advantage /etc/apt/auth.conf.d/90ubuntu-advantage.fips-creds | |
# This will disable the fips service. | |
sudo pro enable fips-updates esm-apps esm-infra --assume-yes | |
# Add the fips credentials back. | |
sudo sh -c 'cat /etc/apt/auth.conf.d/90ubuntu-advantage.fips-creds >> /etc/apt/auth.conf.d/90ubuntu-advantage' | |
sudo rm /etc/apt/auth.conf.d/90ubuntu-advantage.fips-creds | |
# Make apt credentials accessible to USER. | |
sudo setfacl -m u:$USER:r /etc/apt/auth.conf.d/90ubuntu-advantage | |
# Run tests on Pro and non-Pro real archives. | |
go test ./internal/archive/ -v --real-archive --real-pro-archive |