This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [ '30', '31', '32', '33' ] | |
variant: [ '', '-emulator', '-ndk', '-stf-client' ] | |
needs: [checks-hadolint, checks-shfmt, checks-shellcheck, checks-update] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
if: github.ref == 'refs/heads/master' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Login to GAR | |
if: github.ref == 'refs/heads/master' | |
uses: docker/login-action@v2 | |
with: | |
registry: europe-west1-docker.pkg.dev | |
username: _json_key | |
password: ${{ secrets.GCR_JSON_KEY }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
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/master') }} | |
- name: Cache Mode | |
id: cache-mode | |
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 | |
uses: docker/build-push-action@v4 | |
with: | |
context: ${{ matrix.version }}${{ matrix.variant }} | |
push: ${{ github.ref == 'refs/heads/master' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=${{ steps.cache-mode.outputs.mode }} |