Skip to content

Commit e342c83

Browse files
committed
Refactor Android build workflow to streamline Docker image handling
Update GitHub Actions workflow to standardize image tagging and checking logic. Simplify condition handling for reusing existing Docker images or building new ones, ensuring consistent behavior and improved maintainability.
1 parent a570806 commit e342c83

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

.github/workflows/android-build-test.yml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ jobs:
1818
packages: write
1919
steps:
2020
- uses: actions/checkout@v4
21+
2122
- name: Get Dockerfile hash tag
2223
id: meta-hash
2324
uses: docker/metadata-action@v5
2425
with:
2526
images: ghcr.io/mlcommons/mobile_app_open-android
26-
tags: type=content,path=flutter/android/docker/Dockerfile
27+
tags: type=sha256,path=flutter/android/docker/Dockerfile
2728

2829
- name: Set up Docker Buildx
2930
uses: docker/setup-buildx-action@v3
31+
3032
- name: Log in to the Container registry
3133
uses: docker/login-action@v3
3234
with:
@@ -37,36 +39,33 @@ jobs:
3739
- name: Check if image exists
3840
id: check-image
3941
run: |
40-
docker manifest inspect ${{ steps.meta-hash.outputs.tags }} > /dev/null
42+
if docker manifest inspect ${{ steps.meta-hash.outputs.tags }} > /dev/null; then
43+
echo "Image with Dockerfile hash tag exists."
44+
echo "exists=true" >> $GITHUB_OUTPUT
45+
else
46+
echo "Image with Dockerfile hash tag does not exist."
47+
echo "exists=false" >> $GITHUB_OUTPUT
48+
fi
4149
continue-on-error: true
4250

4351
- name: Pull and retag existing image
44-
if: steps.check-image.outcome == 'success'
52+
if: steps.check-image.outputs.exists == 'true'
4553
run: |
4654
docker pull ${{ steps.meta-hash.outputs.tags }}
4755
docker tag ${{ steps.meta-hash.outputs.tags }} ghcr.io/mlcommons/mobile_app_open-android:${{ github.run_number }}
4856
docker push ghcr.io/mlcommons/mobile_app_open-android:${{ github.run_number }}
4957
50-
- name: Extract metadata for new Docker image
51-
if: steps.check-image.outcome != 'success'
52-
id: meta-new
53-
uses: docker/metadata-action@v5
54-
with:
55-
images: ghcr.io/mlcommons/mobile_app_open-android
56-
flavor: latest=true
57-
tags: |
58-
type=raw,value=${{ github.run_number }}
59-
type=content,path=flutter/android/docker/Dockerfile
60-
6158
- name: Build and push new Docker image
62-
if: steps.check-image.outcome != 'success'
59+
if: steps.check-image.outputs.exists != 'true'
6360
uses: docker/build-push-action@v5
6461
with:
6562
context: flutter/android/docker
6663
file: flutter/android/docker/Dockerfile
6764
push: true
68-
tags: ${{ steps.meta-new.outputs.tags }}
69-
labels: ${{ steps.meta-new.outputs.labels }}
65+
tags: |
66+
${{ steps.meta-hash.outputs.tags }}
67+
ghcr.io/mlcommons/mobile_app_open-android:${{ github.run_number }}
68+
labels: ${{ steps.meta-hash.outputs.labels }}
7069
cache-from: type=gha
7170
cache-to: type=gha,mode=max
7271

0 commit comments

Comments
 (0)