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
Changes from 8 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
60 changes: 37 additions & 23 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
name: Build firmwares

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

env:
REGISTRY: ghcr.io
Expand All @@ -22,39 +15,60 @@ jobs:
packages: write
steps:
- uses: actions/[email protected]
- 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/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create container name
id: create-container-info
run: |
base_image=$(echo ${{ github.event.pull_request.base.repo.full_name }} | tr [:upper:] [:lower:])
head_image=$(echo ${{ github.event.pull_request.head.repo.full_name }} | tr [:upper:] [:lower:])
tag_name="${{ hashFiles('Dockerfile') }}"

# Default to building a new container under the original repo
image_name=$head_image
build=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=false
fi

# Check if we can use the head image (PR)
if docker manifest inspect ${{ env.REGISTRY }}/$head_image:$tag_name; then
image_name=$head_image
build=false
fi

echo "build=$build" >> $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/[email protected]
if: steps.create-container-info.outputs.build == 'true'
- name: Build and Push
uses: docker/[email protected]
if: steps.create-container-info.outputs.build == '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: ${{ steps.create-container-info.outputs.tag_name }}
cache-from: ${{ steps.create-container-info.outputs.image_name }}:cache-${{ steps.create-container-info.outputs.tag_name }}
cache-to: ${{ steps.create-container-info.outputs.image_name }}:cache-${{ steps.create-container-info.outputs.tag_name }}
push: true
outputs:
container_name: ${{ steps.create-container-name.outputs.container_name }}
tag_name: ${{ steps.create-container-info.outputs.tag_name }}
image_name: ${{ steps.create-container-info.outputs.image_name }}
container_name: ${{ steps.create-container-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