-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow PR to build firmware * Add a no-op step * Run CI on any push * Add missing `runs-on` * Fix typo in `get-build-container-names` output * Only push the new container if the GitHub event is itself `push` * Only build the new container if necessary * Move `env` variable to step output * Only ignore a few paths instead of listing all paths to include * Use a Python script to query the GitHub API to determine `base` and `head` * Use correct environment variable name * Revert "Use correct environment variable name" This reverts commit bfc2f70. * Revert "Use a Python script to query the GitHub API to determine `base` and `head`" This reverts commit 7bf64ee. * Handle `push` and `pull_request` separately * Forgot `tag_name` * Detect the current PR * Remove extraneous parentheses * Ensure CI works for both pull requests and pushes * Fix shell script logic * Use correct step name in `steps.` * Oops, too many replaces * Truncate the tag name to 16 characters * Include the registry name in Docker steps * Revert removal of `actions/checkout` * Download Gecko SDKs as ZIP files * Unzip quietly * Fail if we must build a container in a PR
- Loading branch information
Showing
2 changed files
with
64 additions
and
30 deletions.
There are no files selected for viewing
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
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: | ||
- '*' | ||
|
||
paths-ignore: | ||
- '.gitignore' | ||
- 'README.md' | ||
env: | ||
REGISTRY: ghcr.io | ||
|
||
|
@@ -22,39 +20,73 @@ 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: 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/[email protected] | ||
if: steps.read-repo-info.outputs.build_image == 'true' | ||
- name: Build and Push | ||
uses: docker/[email protected] | ||
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 }} | ||
|
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