-
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.
Ensure CI works for both pull requests and pushes
- Loading branch information
Showing
1 changed file
with
19 additions
and
25 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,6 +1,10 @@ | ||
name: Build firmwares | ||
|
||
on: | ||
pull_request: | ||
paths-ignore: | ||
- '.gitignore' | ||
- 'README.md' | ||
push: | ||
paths-ignore: | ||
- '.gitignore' | ||
|
@@ -22,29 +26,17 @@ jobs: | |
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Get current PR | ||
id: get-current-pr | ||
uses: 8BitJonny/[email protected] | ||
- name: Read repository information (PR) | ||
id: read-repo-info-pr | ||
if: steps.get-current-pr.outputs.pr_found == 'true' | ||
run: | | ||
base_image=$(echo ${{ fromJSON(steps.get-current-pr.outputs.pr).base.repo.full_name }} | tr [:upper:] [:lower:]) | ||
head_image=$(echo ${{ fromJSON(steps.get-current-pr.outputs.pr).head.repo.full_name }} | tr [:upper:] [:lower:]) | ||
echo "base_image=$base_image" >> $GITHUB_OUTPUT | ||
echo "head_image=$base_image" >> $GITHUB_OUTPUT | ||
- name: Read repository information (no PR) | ||
- name: Read repository information | ||
id: read-repo-info | ||
if: steps.get-current-pr.outputs.pr_found == 'false' | ||
run: | | ||
base_image=$(echo ${{ github.repository }} | tr [:upper:] [:lower:]) | ||
echo "base_image=$base_image" >> $GITHUB_OUTPUT | ||
echo "head_image=$base_image" >> $GITHUB_OUTPUT | ||
- name: Create container info | ||
id: create-container-info | ||
run: | | ||
base_image="${{ steps.read-repo-info.outputs.base_image || steps.read-repo-info-pr.outputs.base_image }}" | ||
head_image="${{ steps.read-repo-info.outputs.head_image || steps.read-repo-info-pr.outputs.head_image }}" | ||
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="${{ hashFiles('Dockerfile') }}" | ||
# Default to building a new container under the original repo | ||
|
@@ -57,10 +49,12 @@ jobs: | |
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 | ||
# 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=false | ||
fi | ||
fi | ||
echo "build=$build" >> $GITHUB_OUTPUT | ||
|