Skip to content

Merge pull request #18 from ekreative/actions #41

Merge pull request #18 from ekreative/actions

Merge pull request #18 from ekreative/actions #41

Workflow file for this run

name: Create and publish a Docker image
# Cache setup: https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md
# Multi push: https://github.com/docker/build-push-action/blob/master/docs/advanced/push-multi-registries.md
on:
push:
branches: ['*']
jobs:
checks-update:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check update has been run
run: |
./update.sh
git diff --quiet
checks-hadolint:
runs-on: ubuntu-latest
permissions:
contents: read
container: hadolint/hadolint:latest-debian
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check hadolint
run: |
hadolint */Dockerfile
checks-shfmt:
runs-on: ubuntu-latest
permissions:
contents: read
container: mvdan/shfmt:latest-alpine
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check shfmt
run: |
shfmt -i 2 -ci -d update.sh
shfmt -i 2 -ci -d tools/adb-all
shfmt -i 2 -ci -d tools/license_accepter
shfmt -i 2 -ci -d tools-emulator/android-start-emulator
shfmt -i 2 -ci -d tools-emulator/android-wait-for-emulator
checks-shellcheck:
runs-on: ubuntu-latest
permissions:
contents: read
container: koalaman/shellcheck-alpine:latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check shellcheck
run: |
shellcheck update.sh
shellcheck tools/adb-all
shellcheck tools/license_accepter
shellcheck tools-emulator/android-start-emulator
shellcheck tools-emulator/android-wait-for-emulator
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
version: [ '32', '33', '34' ]
variant: [ '', '-emulator', '-ndk', '-stf-client', '-jdk17', '-jdk11' ]
needs: [checks-hadolint, checks-shfmt, checks-shellcheck, checks-update]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check Exists
id: check-dir
run: |
if [ ! -d ${{ matrix.version }}${{ matrix.variant }} ]; then
echo "Directory ${{ matrix.version }}${{ matrix.variant }} does not exist"
echo "skipdir=true" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
if: steps.check-dir.outputs.skipdir != 'true'
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: steps.check-dir.outputs.skipdir != 'true' && github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to GAR
if: steps.check-dir.outputs.skipdir != 'true' && github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
registry: europe-west1-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}
- name: Extract metadata (tags, labels) for Docker
id: meta
if: steps.check-dir.outputs.skipdir != 'true'
uses: docker/metadata-action@v5
with:
images: |
ekreative/android
europe-west1-docker.pkg.dev/ekreative-internal/ci/android
tags: |
type=raw,value=${{ matrix.version }}${{ matrix.variant }}
flavor: |
latest=${{ toJSON(matrix.version == '31' && matrix.variant == '' && github.ref == 'refs/heads/main') }}
- name: Cache Mode
id: cache-mode
if: steps.check-dir.outputs.skipdir != 'true'
run: |
if [ "$VARIANT" == '-emulator' ]; then
echo "::set-output name=mode::min"
else
echo "::set-output name=mode::max"
fi
env:
VARIANT: ${{ matrix.variant }}
- name: Build and push Docker image
if: steps.check-dir.outputs.skipdir != 'true'
uses: docker/build-push-action@v5
with:
context: ${{ matrix.version }}${{ matrix.variant }}
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=${{ steps.cache-mode.outputs.mode }}