Move permissions at top level #4
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: Build & test x86_64 | ||
on: | ||
workflow_call: | ||
inputs: | ||
flavor: | ||
required: true | ||
type: string | ||
concurrency: | ||
group: ci-${{ inputs.flavor }}-x86_64-${{ github.head_ref || github.ref }}-${{ github.repository }} | ||
cancel-in-progress: true | ||
jobs: | ||
permissions: | ||
content: read | ||
build-os: | ||
permissions: | ||
packages: write | ||
runs-on: ubuntu-latest | ||
env: | ||
FLAVOR: ${{ inputs.flavor }} | ||
ARCH: x86_64 | ||
TOOLKIT_REPO: ghcr.io/${{ github.repository }}/elemental-cli | ||
REPO: ghcr.io/${{ github.repository }}/elemental-${{ inputs.flavor }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "${{ github.event.pull_request.head.sha }}" | ||
- run: | | ||
git fetch --prune --unshallow | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build OS | ||
run: | | ||
make pull-toolkit | ||
make ARCH=${{ env.ARCH }} DOCKER_ARGS=--load build-os | ||
make ARCH=${{ env.ARCH }} DOCKER_ARGS=--push build-os | ||
build-iso: | ||
needs: | ||
- build-os | ||
runs-on: ubuntu-latest | ||
env: | ||
FLAVOR: ${{ inputs.flavor }} | ||
ARCH: x86_64 | ||
TOOLKIT_REPO: ghcr.io/${{github.repository}}/elemental-cli | ||
REPO: ghcr.io/${{ github.repository }}/elemental-${{ inputs.flavor }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "${{ github.event.pull_request.head.sha }}" | ||
- run: | | ||
git fetch --prune --unshallow | ||
- name: Cached ISO | ||
id: cache-iso | ||
uses: actions/cache/restore@v4 | ||
env: | ||
cache-name: pr-iso-build-x86_64-${{ inputs.flavor }} | ||
enableCrossOsArchive: true | ||
lookup-only: true | ||
with: | ||
path: /tmp/*.iso | ||
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }} | ||
- if: ${{ steps.cache-iso.outputs.cache-hit != 'true' }} | ||
name: Build ISO | ||
run: | | ||
make pull-toolkit pull-os | ||
make build-iso | ||
sudo mv build/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.iso /tmp/ | ||
- if: ${{ steps.cache-iso.outputs.cache-hit != 'true' }} | ||
name: Save ISO | ||
id: save-iso | ||
uses: actions/cache/save@v4 | ||
env: | ||
cache-name: pr-iso-build-x86_64-${{ inputs.flavor }} | ||
with: | ||
path: /tmp/*.iso | ||
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }} | ||
enableCrossOsArchive: true | ||
build-disk: | ||
needs: | ||
- build-os | ||
runs-on: ubuntu-latest | ||
env: | ||
FLAVOR: ${{ inputs.flavor }} | ||
ARCH: x86_64 | ||
TOOLKIT_REPO: ghcr.io/${{github.repository}}/elemental-cli | ||
REPO: ghcr.io/${{ github.repository }}/elemental-${{ inputs.flavor }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "${{ github.event.pull_request.head.sha }}" | ||
- run: | | ||
git fetch --prune --unshallow | ||
- name: Checks cached Disk | ||
uses: actions/cache/restore@v4 | ||
id: cache-check | ||
env: | ||
cache-name: pr-disk-build-x86_64-${{ inputs.flavor }} | ||
with: | ||
path: /tmp/*.qcow2 | ||
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }} | ||
enableCrossOsArchive: true | ||
lookup-only: true | ||
- if: ${{ steps.cache-check.outputs.cache-hit != 'true' }} | ||
name: Cleanup worker | ||
run: | | ||
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android | ||
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET | ||
sudo df -h | ||
- if: ${{ steps.cache-check.outputs.cache-hit != 'true' }} | ||
name: Install to disk | ||
run: | | ||
sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-utils coreutils | ||
make pull-toolkit pull-os | ||
sudo -E make ARCH=${{ env.ARCH }} build-disk | ||
sudo mv build/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.qcow2 /tmp/ | ||
- if: ${{ steps.cache-check.outputs.cache-hit != 'true' }} | ||
name: Save cached disk | ||
id: cache-disk | ||
uses: actions/cache/save@v4 | ||
env: | ||
cache-name: pr-disk-build-x86_64-${{ inputs.flavor }} | ||
with: | ||
path: /tmp/*.qcow2 | ||
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }} | ||
enableCrossOsArchive: true | ||
detect: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
tests: ${{ steps.detect.outputs.tests }} | ||
upgrade: ${{ steps.image.outputs.upgrade }} | ||
toolkit: ${{ steps.image.outputs.toolkit }} | ||
steps: | ||
- id: detect | ||
env: | ||
FLAVOR: ${{ inputs.flavor }} | ||
run: | | ||
if [ "${FLAVOR}" == green ]; then | ||
echo "tests=['test-upgrade', 'test-downgrade', 'test-recovery', 'test-fallback', 'test-fsck', 'test-grubfallback']" >> $GITHUB_OUTPUT | ||
else | ||
echo "tests=['test-active']" >> $GITHUB_OUTPUT | ||
fi | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "${{ github.event.pull_request.head.sha }}" | ||
- id: image | ||
env: | ||
FLAVOR: ${{ inputs.flavor }} | ||
run: | | ||
git fetch --prune --unshallow | ||
export TAG=$(git describe --tags --candidates=50 --abbrev=0) | ||
export COMMIT=$(git rev-parse --short HEAD) | ||
export VERSION=${TAG}-g${COMMIT} | ||
echo "upgrade=ghcr.io/rancher/elemental-toolkit/elemental-${FLAVOR}:${VERSION}" >> $GITHUB_OUTPUT | ||
echo "toolkit=ghcr.io/rancher/elemental-toolkit/elemental-cli:${VERSION}" >> $GITHUB_OUTPUT | ||
tests-matrix: | ||
needs: | ||
- build-disk | ||
- detect | ||
runs-on: ubuntu-latest | ||
env: | ||
FLAVOR: ${{ inputs.flavor }} | ||
ARCH: x86_64 | ||
COS_TIMEOUT: 1600 | ||
UPGRADE_ARGS: --toolkit-image=${{ needs.detect.outputs.toolkit }} --upgrade-image=${{ needs.detect.outputs.upgrade }} | ||
strategy: | ||
matrix: | ||
test: ${{ fromJson(needs.detect.outputs.tests) }} | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "${{ github.event.pull_request.head.sha }}" | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
- name: Install deps | ||
run: | | ||
make test-deps | ||
- run: | | ||
git fetch --prune --unshallow | ||
- if: ${{ matrix.test == 'test-upgrade' }} | ||
name: Download specific disk | ||
run: | | ||
wget -q --tries=3 https://github.com/rancher/elemental-toolkit/releases/download/v1.1.4/elemental-${{ inputs.flavor }}-v1.1.4.${{ env.ARCH }}.qcow2 -O /tmp/elemental-${{ inputs.flavor }}.${{ env.ARCH }}.qcow2 | ||
- if: ${{ matrix.test != 'test-upgrade' }} | ||
name: Cached Disk | ||
id: cache-disk | ||
uses: actions/cache/restore@v4 | ||
env: | ||
cache-name: pr-disk-build-x86_64-${{ inputs.flavor }} | ||
with: | ||
path: /tmp/*.qcow2 | ||
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }} | ||
enableCrossOsArchive: true | ||
fail-on-cache-miss: true | ||
- name: Enable KVM group perms | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install qemu qemu-utils ovmf qemu-system-x86 | ||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | ||
sudo udevadm control --reload-rules | ||
sudo udevadm trigger --name-match=kvm | ||
- name: Run ${{ matrix.test }} | ||
run: | | ||
make DISK=/tmp/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.qcow2 ELMNTL_TARGETARCH=${{ env.ARCH }} ELMNTL_FIRMWARE=/usr/share/OVMF/OVMF_CODE.fd ${{ matrix.test }} | ||
- name: Upload serial console for ${{ matrix.test }} | ||
uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: serial-${{ env.ARCH }}-${{ env.FLAVOR }}-${{ matrix.test }}.log | ||
path: tests/serial.log | ||
if-no-files-found: error | ||
overwrite: true | ||
- name: Upload qemu stdout for ${{ matrix.test }} | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: vmstdout-${{ env.ARCH }}-${{ env.FLAVOR }}-${{ matrix.test }}.log | ||
path: tests/vmstdout | ||
if-no-files-found: error | ||
overwrite: true | ||
- name: Stop test VM | ||
if: always() | ||
run: | | ||
make test-clean | ||
test-installer: | ||
needs: | ||
- build-iso | ||
- detect | ||
runs-on: ubuntu-latest | ||
env: | ||
FLAVOR: ${{ inputs.flavor }} | ||
ARCH: x86_64 | ||
COS_TIMEOUT: 1600 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "${{ github.event.pull_request.head.sha }}" | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
- name: Install deps | ||
run: | | ||
make test-deps | ||
- run: | | ||
git fetch --prune --unshallow | ||
- name: Cached ISO | ||
id: cache-iso | ||
uses: actions/cache/restore@v4 | ||
env: | ||
cache-name: pr-iso-build-x86_64-${{ inputs.flavor }} | ||
with: | ||
path: /tmp/*.iso | ||
key: ${{ env.cache-name }}-${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }} | ||
enableCrossOsArchive: true | ||
fail-on-cache-miss: true | ||
- name: Enable KVM group perms | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install qemu qemu-utils ovmf qemu-system-x86 | ||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | ||
sudo udevadm control --reload-rules | ||
sudo udevadm trigger --name-match=kvm | ||
- name: Run installer test | ||
run: | | ||
make ISO=/tmp/elemental-${{ env.FLAVOR }}.${{ env.ARCH}}.iso ELMNTL_TARGETARCH=${{ env.ARCH }} ELMNTL_FIRMWARE=/usr/share/OVMF/OVMF_CODE.fd test-installer | ||
- name: Upload serial console for installer tests | ||
uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: serial-${{ env.ARCH }}-${{ env.FLAVOR }}-installer.log | ||
path: tests/serial.log | ||
if-no-files-found: error | ||
overwrite: true | ||
- name: Upload qemu stdout for installer tests | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: vmstdout-${{ env.ARCH }}-${{ env.FLAVOR }}-installer.log | ||
path: tests/vmstdout | ||
if-no-files-found: error | ||
overwrite: true | ||
- name: Stop test VM | ||
if: always() | ||
run: | | ||
make test-clean |