Skip to content

Commit 793b007

Browse files
chore: group variables in single step
1 parent fbd4f65 commit 793b007

File tree

1 file changed

+34
-44
lines changed

1 file changed

+34
-44
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,10 @@ jobs:
456456
- "ubuntu-latest"
457457
- "ubuntu-24.04-arm"
458458
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 }}
459+
application_name: ${{ steps.variables.outputs.application_name }}
460+
full_image_name: ${{ steps.variables.outputs.full_image_name }}
461+
registry: ${{ steps.variables.outputs.registry }}
462+
unique_tag: ${{ steps.variables.outputs.unique_tag }}
464463
runs-on: ${{ matrix.runs-on }}
465464
needs:
466465
- calculate-version
@@ -517,84 +516,75 @@ jobs:
517516

518517
# TODO validate no changes between github.event.pull_request.head.sha and the actual current sha (representing the hypothetical merge)
519518

520-
- name: Lowercase the image name
519+
- name: Set variables
521520
shell: bash
522-
id: image_name
523-
run: |
524-
echo "image_name=${IMAGE_NAME,,}" >> ${GITHUB_OUTPUT}
525-
526-
- name: Set Docker tag
527-
shell: bash
528-
id: unique_tag
521+
id: variables
529522
run: |
523+
# This is the unique docker tag
530524
unique_tag=pr-${{ github.event.pull_request.base.sha }}-${{ github.event.pull_request.head.sha }}
531-
echo "unique_tag=${unique_tag##*/}" >> ${GITHUB_OUTPUT}
525+
echo "unique_tag=${unique_tag}" >> ${GITHUB_OUTPUT}
532526
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}
527+
# The application name, used in the Dockerfile
528+
application_name=${{ env.IMAGE_NAME }}
529+
# split at the last / and keep that (kristof-mattei/repo-name -> repo-name)
530+
application_name=${application_name##*/}
531+
# lowercase
532+
application_name=${application_name,,}
533+
echo "application_name=${application_name}" >> ${GITHUB_OUTPUT}
539534
540-
- name: Set registry
541-
shell: bash
542-
id: registry
543-
run: |
535+
# The registry to which we'll push
544536
registry=${{ env.REGISTRY }}
537+
registry=${registry,,}
545538
echo "registry=${registry}" >> ${GITHUB_OUTPUT}
546539
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}
540+
# The full image name, which is the registry, the owner and the repo name
541+
image_name=${{ env.IMAGE_NAME }}
542+
image_name=${image_name,,}
543+
echo "full_image_name=${registry}/${image_name}" >> ${GITHUB_OUTPUT}
554544
555545
# Extract metadata (tags, labels) for Docker
556546
# https://github.com/docker/metadata-action
557547
- name: Extract Docker metadata
558548
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
559549
id: meta
560550
with:
561-
images: ${{ steps.full_image_name.outputs.full_image_name }}
562-
tags: |
563-
type=raw,value=${{ steps.unique_tag.outputs.unique_tag }}
564551
labels: |
565552
org.opencontainers.image.version=pr-${{ github.event.number }}
566553
org.opencontainers.image.source=${{ github.event.pull_request.html_url }}
554+
images: ${{ steps.variables.outputs.full_image_name }}
555+
tags: |
556+
type=raw,value=${{ steps.variables.outputs.unique_tag }}
567557
568-
- name: Log into registry ${{ steps.registry.outputs.registry }}
558+
- name: Log into registry ${{ steps.variables.outputs.registry }}
569559
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
570560
with:
571-
registry: ${{ steps.registry.outputs.registry }}
572-
username: ${{ github.actor }}
573561
password: ${{ secrets.GITHUB_TOKEN }}
562+
registry: ${{ steps.variables.outputs.registry }}
563+
username: ${{ github.actor }}
574564

575565
- name: Build Docker image
576566
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 # v6.17.0
577567
with:
578568
build-args: |
579-
APPLICATION_NAME=${{ steps.application_name.outputs.application_name }}
569+
APPLICATION_NAME=${{ steps.variables.outputs.application_name }}
580570
context: .
581571
# this container is THE PR's artifact, and we will re-tag it
582572
# once the PR has been accepted
583-
tags: ${{ steps.meta.outputs.tags }}
573+
cache-from: type=registry,ref=${{ steps.variables.outputs.full_image_name }}:buildcache-${{ steps.variables.outputs.application_name }}
574+
cache-to: type=registry,ref=${{ steps.variables.outputs.full_image_name }}:buildcache-${{ steps.variables.outputs.application_name }},mode=max
584575
labels: ${{ steps.meta.outputs.labels }}
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
576+
outputs: type=oci,dest=/tmp/${{ steps.variables.outputs.unique_tag }}.tar
587577
platforms: linux/amd64, linux/arm64
588-
outputs: type=oci,dest=/tmp/${{ steps.unique_tag.outputs.unique_tag }}.tar
578+
tags: ${{ steps.meta.outputs.tags }}
589579

590580
- name: Upload artifact
591581
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
592582
if: |
593583
matrix.runs-on == 'ubuntu-latest'
594584
with:
595-
name: container-${{ steps.application_name.outputs.application_name }}
596-
path: /tmp/${{ steps.unique_tag.outputs.unique_tag }}.tar
597585
if-no-files-found: error
586+
name: container-${{ steps.variables.outputs.application_name }}
587+
path: /tmp/${{ steps.variables.outputs.unique_tag }}.tar
598588
retention-days: 1
599589

600590
docker-publish:

0 commit comments

Comments
 (0)