diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 63e52a8..200e461 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -39,8 +39,9 @@ jobs: fetch-depth: 0 fetch-tags: 'true' - - name: Docker meta - id: meta + - name: Docker meta for GHCR + if: github.event_name != 'pull_request' + id: meta_ghcr uses: docker/metadata-action@v5 with: images: | @@ -51,15 +52,29 @@ jobs: type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} + - name: Docker meta for Docker Hub + if: github.event_name == 'pull_request' + id: meta_docker + uses: docker/metadata-action@v5 + with: + images: | + docker.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - name: Buildah Build id: build-image uses: redhat-actions/buildah-build@v2 with: containerfiles: Containerfile - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + tags: ${{ steps.meta_ghcr.outputs.tags || steps.meta_docker.outputs.tags }} + labels: ${{ steps.meta_ghcr.outputs.labels || steps.meta_docker.outputs.labels }} - - name: Push image + - name: Push image to GHCR + if: github.event_name != 'pull_request' uses: redhat-actions/push-to-registry@v2 with: image: ${{ steps.build-image.outputs.image }} @@ -67,6 +82,15 @@ jobs: username: ${{ github.actor }} password: ${{ github.token }} + - name: Push image to Docker + if: github.event_name == 'pull_request' + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + username: ${{ secrets.DOCKER_LOGIN }} + password: ${{ secrets.DOCKER_TOKEN }} + build-and-push-iso: name: Build ISO runs-on: ubuntu-latest diff --git a/action.yml b/action.yml index 84f9337..53796f9 100644 --- a/action.yml +++ b/action.yml @@ -131,16 +131,19 @@ runs: ACTION_REF: ${{ github.action_ref }} shell: bash run: | + image="ghcr.io/jasonn3/build-container-installer" # Check if running inside of the action repo if [[ -z "${ACTION_REPO}" || "${ACTION_REPO}" == "${{ github.repository }}" ]] then if [[ "${{ github.ref_name }}" =~ (.*)/merge ]] - then tag=pr-${BASH_REMATCH[1]} + then + tag="pr-${BASH_REMATCH[1]}" + image="docker.io/jasonn3/build-container-installer" else - tag=${{ github.ref_name }} + tag="${{ github.ref_name }}" fi else - tag=${ACTION_REF} + tag="${ACTION_REF}" fi if [[ "${{ inputs.enable_cache_dnf }}" == "true" ]] then @@ -167,7 +170,7 @@ runs: vars="${vars} FLATPAK_REMOTE_REFS_DIR=\"${{ inputs.flatpak_remote_refs_dir }}\"" fi fi - docker run --privileged --volume ${{ github.workspace }}:/github/workspace/ ${cache} ghcr.io/jasonn3/build-container-installer:${tag} \ + docker run --privileged --volume ${{ github.workspace }}:/github/workspace/ ${cache} ${image}:${tag} \ ADDITIONAL_TEMPLATES="${{ inputs.additional_templates }}" \ ARCH="${{ inputs.arch }}" \ DNF_CACHE="/cache/dnf" \ diff --git a/tests/repo/vars.sh b/tests/repo/vars.sh index e9867bf..2e4302e 100644 --- a/tests/repo/vars.sh +++ b/tests/repo/vars.sh @@ -34,4 +34,6 @@ do echo "$var not found in action.yml" result=1 fi -done \ No newline at end of file +done + +exit ${result} \ No newline at end of file