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

Allow PRs to build images #54

Merged
merged 27 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eb52627
Allow PR to build firmware
puddly May 1, 2024
82bec23
Add a no-op step
puddly May 1, 2024
51de299
Run CI on any push
puddly May 1, 2024
665bd69
Add missing `runs-on`
puddly May 1, 2024
2bf77b5
Fix typo in `get-build-container-names` output
puddly May 1, 2024
44b250e
Only push the new container if the GitHub event is itself `push`
puddly May 1, 2024
b71277e
Only build the new container if necessary
puddly May 1, 2024
32afeb4
Move `env` variable to step output
puddly May 1, 2024
c1e64e8
Only ignore a few paths instead of listing all paths to include
puddly May 1, 2024
7bf64ee
Use a Python script to query the GitHub API to determine `base` and `…
puddly May 1, 2024
bfc2f70
Use correct environment variable name
puddly May 1, 2024
9b0c570
Revert "Use correct environment variable name"
puddly May 1, 2024
eccf22c
Revert "Use a Python script to query the GitHub API to determine `bas…
puddly May 1, 2024
bfe4bc9
Handle `push` and `pull_request` separately
puddly May 1, 2024
ed4c28e
Forgot `tag_name`
puddly May 1, 2024
01fdab9
Detect the current PR
puddly May 1, 2024
00e09a5
Remove extraneous parentheses
puddly May 1, 2024
c87815f
Ensure CI works for both pull requests and pushes
puddly May 2, 2024
13d64a4
Fix shell script logic
puddly May 2, 2024
dc4dfcd
Use correct step name in `steps.`
puddly May 2, 2024
7abfe1d
Oops, too many replaces
puddly May 2, 2024
b14e6ce
Truncate the tag name to 16 characters
puddly May 3, 2024
d94a823
Include the registry name in Docker steps
puddly May 3, 2024
0e4000a
Revert removal of `actions/checkout`
puddly May 3, 2024
469fae7
Download Gecko SDKs as ZIP files
puddly May 3, 2024
db827cf
Unzip quietly
puddly May 3, 2024
bcbf8d4
Fail if we must build a container in a PR
puddly May 3, 2024
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
80 changes: 56 additions & 24 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
name: Build firmwares

on:
pull_request:
paths-ignore:
- '.gitignore'
- 'README.md'
push:
paths:
- Dockerfile
- .github/workflows/build.yaml
- manifests/**/*.yaml
branches:
- main
tags:
- '*'
puddly marked this conversation as resolved.
Show resolved Hide resolved

paths-ignore:
- '.gitignore'
- 'README.md'
env:
REGISTRY: ghcr.io

Expand All @@ -22,39 +20,73 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v4.1.4
- name: Create container name
id: create-container-name
run: |
repository_owner=$(echo $GITHUB_REPOSITORY_OWNER | tr [:upper:] [:lower:])
image_name="${{ env.REGISTRY }}/$repository_owner/silabs-firmware-builder"
tag_name="${{ hashFiles('Dockerfile') }}"

echo "image_name=$image_name" >> $GITHUB_OUTPUT
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT
echo "container_name=$image_name:$tag_name" >> $GITHUB_OUTPUT
- name: Log in to the GitHub container registry
uses: docker/login-action@v3.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Read repository information
id: read-repo-info
run: |
if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then
base_image=$(echo ${{ github.event.pull_request.base.repo.full_name }} | awk '{print tolower($0)}')
head_image=$(echo ${{ github.event.pull_request.head.repo.full_name }} | awk '{print tolower($0)}')
else
base_image=$(echo ${{ github.repository }} | awk '{print tolower($0)}')
head_image=$(echo ${{ github.repository }} | awk '{print tolower($0)}')
fi

tag_name=$(echo "${{ hashFiles('Dockerfile') }}" | cut -c-16)

# Default to building a new container under the original repo
image_name=$head_image
build_image=true

# Check if we can use the base image (Nabu Casa)
if docker manifest inspect ${{ env.REGISTRY }}/$base_image:$tag_name; then
image_name=$base_image
build_image=false
fi

# Check if we can use the head image (if this is a PR)
if [[ $base_image != $head_image ]]; then
if docker manifest inspect ${{ env.REGISTRY }}/$head_image:$tag_name; then
image_name=$head_image
build_image=false
fi
fi

if [[ $build_image == "true" && $GITHUB_EVENT_NAME == "pull_request" ]]; then
echo "Cannot build a new container within a PR. Please re-run this action after $head_image:$tag_name is built."
exit 1
fi

echo "build_image=$build_image" >> $GITHUB_OUTPUT
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT
echo "image_name=$image_name" >> $GITHUB_OUTPUT
echo "container_name=${{ env.REGISTRY }}/$image_name:$tag_name" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.3.0
if: steps.read-repo-info.outputs.build_image == 'true'
- name: Build and Push
uses: docker/build-push-action@v5.3.0
if: steps.read-repo-info.outputs.build_image == 'true'
with:
context: .
file: Dockerfile
tags: ${{ steps.create-container-name.outputs.container_name }}
cache-from: ${{ steps.create-container-name.outputs.image_name }}:cache-${{ steps.create-container-name.outputs.tag_name }}
cache-to: ${{ steps.create-container-name.outputs.image_name }}:cache-${{ steps.create-container-name.outputs.tag_name }}
tags: ${{ env.REGISTRY }}/${{ steps.read-repo-info.outputs.image_name }}:${{ steps.read-repo-info.outputs.tag_name }}
cache-from: ${{ env.REGISTRY }}/${{ steps.read-repo-info.outputs.image_name }}:cache-${{ steps.read-repo-info.outputs.tag_name }}
cache-to: ${{ env.REGISTRY }}/${{ steps.read-repo-info.outputs.image_name }}:cache-${{ steps.read-repo-info.outputs.tag_name }}
push: true
outputs:
container_name: ${{ steps.create-container-name.outputs.container_name }}
tag_name: ${{ steps.read-repo-info.outputs.tag_name }}
image_name: ${{ steps.read-repo-info.outputs.image_name }}
container_name: ${{ steps.read-repo-info.outputs.container_name }}


list-manifests:
name: List firmware manifests
needs: build-container
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
Expand Down
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN \
# is known to be working with Commander_linux_x86_64_1v15p0b1306.tar.bz).
RUN \
curl -O https://www.silabs.com/documents/login/software/SimplicityCommander-Linux.zip \
&& unzip SimplicityCommander-Linux.zip \
&& unzip -q SimplicityCommander-Linux.zip \
&& tar -C /opt -xjf SimplicityCommander-Linux/Commander_linux_x86_64_*.tar.bz \
&& rm -r SimplicityCommander-Linux \
&& rm SimplicityCommander-Linux.zip
Expand All @@ -34,7 +34,7 @@ ENV PATH="$PATH:/opt/commander"
# Install Silicon Labs Configurator (slc)
RUN \
curl -O https://www.silabs.com/documents/login/software/slc_cli_linux.zip \
&& unzip -d /opt slc_cli_linux.zip \
&& unzip -q -d /opt slc_cli_linux.zip \
&& rm slc_cli_linux.zip

ENV PATH="$PATH:/opt/slc_cli"
Expand All @@ -53,13 +53,15 @@ RUN \

# Gecko SDK 4.4.0
RUN \
git clone --depth 1 -b v4.4.0 https://github.com/SiliconLabs/gecko_sdk.git gecko_sdk_4.4.0 \
&& rm -rf gecko_sdk_4.4.0/.git
curl -o gecko_sdk_4.4.0.zip -L https://github.com/SiliconLabs/gecko_sdk/releases/download/v4.4.0/gecko-sdk.zip \
&& unzip -q -d gecko_sdk_4.4.0 gecko_sdk_4.4.0.zip \
&& rm gecko_sdk_4.4.0.zip

# Gecko SDK 4.3.1
RUN \
git clone --depth 1 -b v4.3.1 https://github.com/SiliconLabs/gecko_sdk.git gecko_sdk_4.3.1 \
&& rm -rf gecko_sdk_4.3.1/.git
curl -o gecko_sdk_4.3.1.zip -L https://github.com/SiliconLabs/gecko_sdk/releases/download/v4.3.1/gecko-sdk.zip \
&& unzip -q -d gecko_sdk_4.3.1 gecko_sdk_4.3.1.zip \
&& rm gecko_sdk_4.3.1.zip

ARG USERNAME=builder
ARG USER_UID=1000
Expand Down