Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow toolkit #1946

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Build
on:
push:
tags:
- v**
pull_request_target:
paths:
- tests/**
- make/**
- Makefile
- .github/**
- pkg/**
- cmd/**
- go.mod
- go.sum
- examples/**

jobs:
detect:
runs-on: ubuntu-latest
outputs:
flavor: ${{ steps.set-matrix.outputs.flavor }}
platform: ${{ steps.set-platform.outputs.platform }}
steps:
- id: set-matrix
run: |
if [ "${{ contains(github.event.pull_request.labels.*.name, 'all-distros') }}" == "true" ]; then
echo "flavor=['green', 'tumbleweed', 'blue', 'orange']" >> $GITHUB_OUTPUT
else
echo "flavor=['green']" >> $GITHUB_OUTPUT
fi
- id: set-platform
run: |
if [ "${{ startsWith(github.event.ref, 'refs/tags/v') }}" == "true" ]; then
echo "platform='linux/x86_64,linux/arm64" >> $GITHUB_OUTPUT
else
echo "platform='linux/x86_64'" >> $GITHUB_OUTPUT
fi

build-toolkit:
permissions:
packages: write
runs-on: ubuntu-latest
env:
PLATFORM: ${{ needs.detect.outputs.platform }}
TOOLKIT_REPO: ghcr.io/${{github.repository}}/elemental-cli
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.merge_commit_sha }}"
- run: |
git fetch --prune --unshallow
- id: set-version
run: |
git describe --tags --candidates=50 >> $GITHUB_OUTPUT
- name: Log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build toolkit
run: |
make DOCKER_ARGS=--push build

build-matrix:
needs:
- detect
- build-toolkit
strategy:
matrix:
flavor: ${{fromJson(needs.detect.outputs.flavor)}}
fail-fast: false
uses: ./.github/workflows/build_and_test_x86.yaml
with:
flavor: ${{ matrix.flavor }}

cleanup:
needs:
- build-toolkit
- build-matrix
steps:
- uses: actions/delete-package-versions@v4
if: ${{ !startsWith(github.event.ref, 'refs/tags/v') }}
with:
package-version-ids: ${{ needs.build-toolkit.outputs.version }}
owner: ${{ github.owner }}
package-name: elemental-toolkit/elemental-cli
package-type: container
78 changes: 54 additions & 24 deletions .github/workflows/build_and_test_x86.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,48 @@ concurrency:
cancel-in-progress: true

jobs:
# detect step checks what machines the later steps should run on
detect:
build-os:
permissions:
packages: write
runs-on: ubuntu-latest
outputs:
tests: ${{ steps.detect.outputs.tests }}
env:
FLAVOR: ${{ inputs.flavor }}
ARCH: x86_64
TOOLKIT_REPO: ghcr.io/${{ github.repository }}/elemental-cli
REPO: ghcr.io/${{ github.repository }}/elemental-${{ inputs.flavor }}
steps:
- id: detect
env:
FLAVOR: ${{ inputs.flavor }}
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.merge_commit_sha }}"
- run: |
git fetch --prune --unshallow
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- 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 toolkit
run: |
if [ "${FLAVOR}" == green ]; then
echo "tests=['test-upgrade', 'test-recovery', 'test-fallback', 'test-fsck', 'test-grubfallback']" >> $GITHUB_OUTPUT
else
echo "tests=['test-active']" >> $GITHUB_OUTPUT
fi

make pull-toolkit
make ARCH=${{ env.ARCH }} DOCKER_ARGS=--load build-os
make ARCH=${{ env.ARCH }} DOCKER_ARGS=--push build-os

build-iso:
needs: detect
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.merge_commit_sha }}"
- run: |
git fetch --prune --unshallow
- name: Cached ISO
Expand All @@ -49,10 +66,6 @@ jobs:
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 toolkit
run: |
make build
- if: ${{ steps.cache-iso.outputs.cache-hit != 'true' }}
name: Build ISO
run: |
Expand All @@ -70,13 +83,16 @@ jobs:
enableCrossOsArchive: true

build-disk:
needs: detect
needs:
- build-os
runs-on: ubuntu-latest
env:
FLAVOR: ${{ inputs.flavor }}
ARCH: x86_64
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.merge_commit_sha }}"
- run: |
git fetch --prune --unshallow
- name: Checks cached Disk
Expand All @@ -95,15 +111,10 @@ jobs:
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: Build toolkit
run: |
make build
- 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 ARCH=${{ env.ARCH }} build-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' }}
Expand All @@ -117,6 +128,21 @@ jobs:
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 }}
steps:
- id: detect
env:
FLAVOR: ${{ inputs.flavor }}
run: |
if [ "${FLAVOR}" == green ]; then
echo "tests=['test-upgrade', 'test-recovery', 'test-fallback', 'test-fsck', 'test-grubfallback']" >> $GITHUB_OUTPUT
else
echo "tests=['test-active']" >> $GITHUB_OUTPUT
fi

tests-matrix:
needs:
- build-disk
Expand All @@ -132,6 +158,8 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.merge_commit_sha }}"
- name: Install Go
uses: actions/setup-go@v5
with:
Expand Down Expand Up @@ -189,6 +217,8 @@ jobs:
COS_TIMEOUT: 1600
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.merge_commit_sha }}"
- name: Install Go
uses: actions/setup-go@v5
with:
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/pr.yaml

This file was deleted.

53 changes: 0 additions & 53 deletions .github/workflows/release.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ RUN ARCH=$(uname -m); \
xorriso \
cosign \
gptfdisk \
lvm2
lvm2 && \
zypper cc -a

# Copy the built CLI
COPY --from=elemental-bin /usr/bin/elemental /usr/bin/elemental
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ build:
push-toolkit:
$(DOCKER) push $(TOOLKIT_REPO):$(VERSION)

.PHONY: pull-toolkit
pull-toolkit:
$(DOCKER) pull $(TOOLKIT_REPO):$(VERSION)

.PHONY: build-cli
build-cli:
go build -ldflags '$(LDFLAGS)' -o build/elemental
Expand Down
3 changes: 2 additions & 1 deletion examples/green-rpi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ RUN zypper --non-interactive install --no-recommends -- \
sudo \
curl \
podman \
sed
sed && \
zypper clean --all

# Just add the elemental cli
COPY --from=TOOLKIT /usr/bin/elemental /usr/bin/elemental
Expand Down
3 changes: 2 additions & 1 deletion examples/green/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ RUN ARCH=$(uname -m); \
curl \
iproute2 \
podman \
sed
sed && \
zypper clean --all

# Just add the elemental cli
COPY --from=TOOLKIT /usr/bin/elemental /usr/bin/elemental
Expand Down
3 changes: 2 additions & 1 deletion examples/tumbleweed/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ RUN ARCH=$(uname -m); \
patch \
iproute2 \
podman \
${ADD_PKGS}
${ADD_PKGS} && \
zypper clean --all

# Just add the elemental cli
COPY --from=TOOLKIT /usr/bin/elemental /usr/bin/elemental
Expand Down
Loading