Skip to content

Commit fbd4f65

Browse files
Merge pull request #1894 from kristof-mattei/more-variables
more variables
2 parents dceb28a + 39aecb7 commit fbd4f65

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

.github/workflows/build.yml

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,17 @@ jobs:
455455
runs-on:
456456
- "ubuntu-latest"
457457
- "ubuntu-24.04-arm"
458+
outputs:
459+
application_name: ${{ steps.application_name.outputs.application_name }}
460+
image_name: ${{ steps.image_name.outputs.image_name }}
461+
full_image_name: ${{ steps.full_image_name.outputs.full_image_name }}
462+
registry: ${{ steps.registry.outputs.registry }}
463+
unique_tag: ${{ steps.unique_tag.outputs.unique_tag }}
458464
runs-on: ${{ matrix.runs-on }}
459465
needs:
460466
- calculate-version
461467
# if:
462468
# ... is not needed because calculate-version will not run if we disable building the docker container
463-
env:
464-
APPLICATION_NAME: PLACEHOLDER # overridden in step 'Set application name', this is merely to satisfy the linter
465-
PATH_TO_TAR: PLACEHOLDER # same ^
466-
UNIQUE_TAG: PLACEHOLDER # same ^
467469
steps:
468470
- name: Checkout
469471
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -517,63 +519,81 @@ jobs:
517519

518520
- name: Lowercase the image name
519521
shell: bash
522+
id: image_name
520523
run: |
521-
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
524+
echo "image_name=${IMAGE_NAME,,}" >> ${GITHUB_OUTPUT}
522525
523526
- name: Set Docker tag
524527
shell: bash
528+
id: unique_tag
525529
run: |
526530
unique_tag=pr-${{ github.event.pull_request.base.sha }}-${{ github.event.pull_request.head.sha }}
527-
echo "UNIQUE_TAG=${unique_tag##*/}" >> ${GITHUB_ENV}
531+
echo "unique_tag=${unique_tag##*/}" >> ${GITHUB_OUTPUT}
532+
533+
- name: Set application name
534+
shell: bash
535+
id: application_name
536+
run: |
537+
application_name=${{ github.repository }}
538+
echo "application_name=${application_name##*/}" >> ${GITHUB_OUTPUT}
539+
540+
- name: Set registry
541+
shell: bash
542+
id: registry
543+
run: |
544+
registry=${{ env.REGISTRY }}
545+
echo "registry=${registry}" >> ${GITHUB_OUTPUT}
546+
547+
- name: Set full image name
548+
shell: bash
549+
id: full_image_name
550+
run: |
551+
registry=${{ steps.registry.outputs.registry }}
552+
image_name=${{ steps.image_name.outputs.image_name }}
553+
echo "full_image_name=${registry,,}/${image_name,,}" >> ${GITHUB_OUTPUT}
528554
529555
# Extract metadata (tags, labels) for Docker
530556
# https://github.com/docker/metadata-action
531557
- name: Extract Docker metadata
532558
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
533559
id: meta
534560
with:
535-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
561+
images: ${{ steps.full_image_name.outputs.full_image_name }}
536562
tags: |
537-
type=raw,value=${{ env.UNIQUE_TAG }}
563+
type=raw,value=${{ steps.unique_tag.outputs.unique_tag }}
538564
labels: |
539565
org.opencontainers.image.version=pr-${{ github.event.number }}
540566
org.opencontainers.image.source=${{ github.event.pull_request.html_url }}
541567
542-
- name: Log into registry ${{ env.REGISTRY }}
568+
- name: Log into registry ${{ steps.registry.outputs.registry }}
543569
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
544570
with:
545-
registry: ${{ env.REGISTRY }}
571+
registry: ${{ steps.registry.outputs.registry }}
546572
username: ${{ github.actor }}
547573
password: ${{ secrets.GITHUB_TOKEN }}
548574

549-
- name: Set application name
550-
shell: bash
551-
run: |
552-
application_name=${{ github.repository }}
553-
echo "APPLICATION_NAME=${application_name##*/}" >> ${GITHUB_ENV}
554-
555575
- name: Build Docker image
556576
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 # v6.17.0
557577
with:
558578
build-args: |
559-
APPLICATION_NAME=${{ env.APPLICATION_NAME }}
579+
APPLICATION_NAME=${{ steps.application_name.outputs.application_name }}
560580
context: .
561581
# this container is THE PR's artifact, and we will re-tag it
562582
# once the PR has been accepted
563583
tags: ${{ steps.meta.outputs.tags }}
564584
labels: ${{ steps.meta.outputs.labels }}
565-
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ env.APPLICATION_NAME }}
566-
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ env.APPLICATION_NAME }},mode=max
585+
cache-from: type=registry,ref=${{ steps.full_image_name.outputs.full_image_name }}:buildcache-${{ steps.application_name.outputs.application_name }}
586+
cache-to: type=registry,ref=${{ steps.full_image_name.outputs.full_image_name }}:buildcache-${{ steps.application_name.outputs.application_name }},mode=max
567587
platforms: linux/amd64, linux/arm64
568-
outputs: type=oci,dest=/tmp/${{ env.UNIQUE_TAG }}.tar
588+
outputs: type=oci,dest=/tmp/${{ steps.unique_tag.outputs.unique_tag }}.tar
569589

570590
- name: Upload artifact
571591
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
572592
if: |
573593
matrix.runs-on == 'ubuntu-latest'
574594
with:
575-
name: container-${{ env.APPLICATION_NAME }}
576-
path: /tmp/${{ env.UNIQUE_TAG }}.tar
595+
name: container-${{ steps.application_name.outputs.application_name }}
596+
path: /tmp/${{ steps.unique_tag.outputs.unique_tag }}.tar
577597
if-no-files-found: error
578598
retention-days: 1
579599

@@ -582,9 +602,6 @@ jobs:
582602
runs-on: ubuntu-latest
583603
needs:
584604
- docker-build
585-
env:
586-
APPLICATION_NAME: PLACEHOLDER # overridden in step 'Set application name', this is merely to satisfy the linter
587-
UNIQUE_TAG: PLACEHOLDER # same ^
588605
# Check if the event is not triggered by a fork
589606
if: |
590607
github.event.pull_request.head.repo.full_name == github.repository &&
@@ -600,55 +617,38 @@ jobs:
600617
}
601618
}
602619
603-
- name: Log into registry ${{ env.REGISTRY }}
620+
- name: Log into registry ${{ needs.docker-build.outputs.registry }}
604621
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
605622
with:
606-
registry: ${{ env.REGISTRY }}
623+
registry: ${{ needs.docker-build.outputs.registry }}
607624
username: ${{ github.actor }}
608625
password: ${{ secrets.GITHUB_TOKEN }}
609626

610-
- name: Lowercase the image name
611-
shell: bash
612-
run: |
613-
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
614-
615-
- name: Set application name
616-
shell: bash
617-
run: |
618-
application_name=${{ github.repository }}
619-
echo "APPLICATION_NAME=${application_name##*/}" >> ${GITHUB_ENV}
620-
621-
- name: Set Docker tag (which is also the filename.tar)
622-
shell: bash
623-
run: |
624-
unique_tag=pr-${{ github.event.pull_request.base.sha }}-${{ github.event.pull_request.head.sha }}
625-
echo "UNIQUE_TAG=${unique_tag##*/}" >> ${GITHUB_ENV}
626-
627627
- name: Extract Docker metadata
628628
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
629629
id: meta
630630
with:
631-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
631+
images: ${{ needs.docker-build.outputs.full_image_name }}
632632
tags: |
633633
type=ref,event=pr,suffix=-latest
634-
type=raw,value=${{ env.UNIQUE_TAG }}
634+
type=raw,value=${{ needs.docker-build.outputs.unique_tag }}
635635
636636
- name: Download artifact
637637
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
638638
id: artifact
639639
with:
640640
path: /tmp/container/
641-
name: container-${{ env.APPLICATION_NAME }}
641+
name: container-${{ needs.docker-build.outputs.application_name }}
642642

643643
- name: Load images from artifacts
644644
shell: bash
645645
run: |
646-
docker load --input ${{ steps.artifact.outputs.download-path }}/${{ env.UNIQUE_TAG }}.tar
646+
docker load --input ${{ steps.artifact.outputs.download-path }}/${{ needs.docker-build.outputs.unique_tag }}.tar
647647
648648
- name: Push image to register
649649
shell: bash
650650
run: |
651-
base_tag=$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:%s ' ${{ env.UNIQUE_TAG }})
651+
base_tag=$(printf '${{ needs.docker-build.outputs.full_image_name }}:%s ' ${{ needs.docker-build.outputs.unique_tag }})
652652
653653
docker push ${base_tag}
654654
@@ -659,7 +659,7 @@ jobs:
659659
new_tags="${{ join(steps.meta.outputs.tags, ' ') }}"
660660
new_tags=$(printf -- '--tag %s ' $new_tags)
661661
662-
base_tag=$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:%s ' ${{ env.UNIQUE_TAG }})
662+
base_tag=$(printf '${{ needs.docker-build.outputs.full_image_name }}:%s ' ${{ needs.docker-build.outputs.unique_tag }})
663663
664664
docker buildx imagetools create $new_tags $base_tag
665665

0 commit comments

Comments
 (0)