Skip to content

Commit

Permalink
Ensure CI works for both pull requests and pushes
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed May 2, 2024
1 parent 00e09a5 commit c87815f
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions .github/workflows/build.yaml
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'
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c87815f

Please sign in to comment.