Skip to content

DockerHub

DockerHub #295

Workflow file for this run

name: DockerHub
on:
push:
branches: [main]
paths:
- '.github/workflows/docker_hub.yml'
- '.github/workflows/validate.yml'
- '**/Dockerfile'
- 'Dockerfile'
- 'entrypoint.sh'
- '.github/matrix.json'
schedule:
- cron: 0 21 * * 0
workflow_dispatch:
env:
DOCKER_USER: 41772ki
DOCKER_REPO: danger-swiftlint
jobs:
generate-matrix:
name: Generate matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
name: Set matrix
run: |
matrix=$(cat .github/matrix.json | jq -c .)
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build:
needs: generate-matrix
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(needs.generate-matrix.outputs.matrix).swift_version }}
runs-on: ubuntu-latest
concurrency:
group: ${{ github.head_ref }}-${{ github.workflow }}-${{ matrix.swift_version }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- name: Set SwiftLint Version
id: set-swiftlint-version
run: |
swiftlint_version=$(echo '${{ needs.generate-matrix.outputs.matrix }}' | jq -c '.swiftlint_supported_version' | jq -r '.["${{ matrix.swift_version }}"]')
echo "swiftlint-version=$swiftlint_version" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login DockerHub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Fetch revisions for tools installed in current Docker image
id: revisions
run: |
echo "mint=$(docker run --entrypoint /bin/cat -t ${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:${{ matrix.swift_version }} /.mint_revision)"
echo "swiftlint=$(docker run --entrypoint /bin/cat -t ${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:${{ matrix.swift_version }} /.swiftlint_revision)"
echo "danger-js=$(docker run --entrypoint /bin/cat -t ${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:${{ matrix.swift_version }} /.danger-js_revision)"
echo "danger-swift=$(docker run --entrypoint /bin/cat -t ${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:${{ matrix.swift_version }} /.danger-swift_revision)"
echo "mint=$(docker run --entrypoint /bin/cat -t ${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:${{ matrix.swift_version }} /.mint_revision)" >> $GITHUB_OUTPUT
echo "swiftlint=$(docker run --entrypoint /bin/cat -t ${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:${{ matrix.swift_version }} /.swiftlint_revision)" >> $GITHUB_OUTPUT
echo "danger-js=$(docker run --entrypoint /bin/cat -t ${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:${{ matrix.swift_version }} /.danger-js_revision)" >> $GITHUB_OUTPUT
echo "danger-swift=$(docker run --entrypoint /bin/cat -t ${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:${{ matrix.swift_version }} /.danger-swift_revision)" >> $GITHUB_OUTPUT
- name: Create tags for push
id: create-tags
run: |
LATEST_VERSION="${{ fromJson(needs.generate-matrix.outputs.matrix).swift_version[0] }}"
SWIFT_VERSION="${{ matrix.swift_version }}" BASE_IMAGE=$(eval "echo \"$(cat Dockerfile | grep FROM | awk '{ print $NF }')\"")
docker pull $BASE_IMAGE
SWIFT_VERSION=$(docker run --entrypoint swift "$BASE_IMAGE" --version | grep 'Swift version' | awk '{ print $NF }' | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')
SWIFT_VERSION_MAJOR_MINOR=$(echo $SWIFT_VERSION | sed -E 's/([0-9]*)\.([0-9]*)(\.([0-9]*))?/\1.\2/g')
SWIFT_VERSION_MAJOR=$(echo $SWIFT_VERSION | sed -E 's/([0-9]*)\.([0-9]*)(\.([0-9]*))?/\1/g')
TAGS="[\"$SWIFT_VERSION\", \"$SWIFT_VERSION_MAJOR_MINOR\",\"$SWIFT_VERSION_MAJOR\"]"
if [[ "${{ matrix.swift_version }}" = "$LATEST_VERSION" ]]; then
TAGS=$(echo "$TAGS" | jq -c '. += ["latest"]')
else
TAGS=$(echo "$TAGS" | jq -c '. | del(.[2])')
fi
TAGS=$(echo "$TAGS" | jq -r '. | unique | map("${{ env.DOCKER_USER }}/${{ env.DOCKER_REPO }}:" + .) | join(",")')
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build Docker image
id: build-image
uses: docker/build-push-action@v5
with:
push: false
load: true
tags: ${{ steps.create-tags.outputs.tags }}
build-args: |
SWIFT_VERSION=${{ matrix.swift_version }}
SWIFT_LINT_REVISION=${{ steps.set-swiftlint-version.outputs.swiftlint-version }}
- name: Verify revisions to check if it needs to update image
if: ${{ github.event_name != 'workflow_dispatch' }}
id: needs-update
run: |
IMAGE_ID="$(echo ${{ steps.build-image.outputs.imageid }} | sed -r 's/:/ /g' | awk '{ print $NF }')"
echo "value=false" >> $GITHUB_OUTPUT
BUILT_MINT_REVISION="$(docker run --entrypoint /bin/cat -t "${IMAGE_ID}" /.mint_revision | tr -d '\n')"
CURRENT_MINT_REVISION="$(echo ${{ steps.revisions.outputs.mint }} | tr -d '\n')"
echo "BUILT_MINT_REVISION = $BUILT_MINT_REVISION"
echo "CURRENT_MINT_REVISION = $CURRENT_MINT_REVISION"
if [ "${BUILT_MINT_REVISION::8}" != "${CURRENT_MINT_REVISION::8}" ]; then
echo 'mint updated.'
echo "value=true" >> $GITHUB_OUTPUT
fi
BUILT_SWIFTLINT_REVISION="$(docker run --entrypoint /bin/cat -t "${IMAGE_ID}" /.swiftlint_revision | tr -d '\n')"
CURRENT_SWIFTLINT_REVISION="$(echo ${{ steps.revisions.outputs.swiftlint }} | tr -d '\n')"
echo "BUILT_SWIFTLINT_REVISION = $BUILT_SWIFTLINT_REVISION"
echo "CURRENT_SWIFTLINT_REVISION = $CURRENT_SWIFTLINT_REVISION"
if [ "${BUILT_SWIFTLINT_REVISION::8}" != "${CURRENT_SWIFTLINT_REVISION::8}" ]; then
echo 'swiftlint updated.'
echo "value=true" >> $GITHUB_OUTPUT
fi
BUILT_DANGER_JS_REVISION="$(docker run --entrypoint /bin/cat -t "${IMAGE_ID}" /.danger-js_revision | tr -d '\n')"
CURRENT_DANGER_JS_REVISION="$(echo ${{ steps.revisions.outputs.danger-js }} | tr -d '\n')"
echo "BUILT_DANGER_JS_REVISION = $BUILT_DANGER_JS_REVISION"
echo "CURRENT_DANGER_JS_REVISION = $CURRENT_DANGER_JS_REVISION"
if [ "${BUILT_DANGER_JS_REVISION::8}" != "${CURRENT_DANGER_JS_REVISION::8}" ]; then
echo 'danger-js updated.'
echo "value=true" >> $GITHUB_OUTPUT
fi
BUILT_DANGER_SWIFT_REVISION="$(docker run --entrypoint /bin/cat -t "${IMAGE_ID}" /.danger-swift_revision | tr -d '\n')"
CURRENT_DANGER_SWIFT_REVISION="$(echo ${{ steps.revisions.outputs.danger-swift }} | tr -d '\n')"
echo "BUILT_DANGER_SWIFT_REVISION = $BUILT_DANGER_SWIFT_REVISION"
echo "CURRENT_DANGER_SWIFT_REVISION = $CURRENT_DANGER_SWIFT_REVISION"
if [ "${BUILT_DANGER_SWIFT_REVISION::8}" != "${CURRENT_DANGER_SWIFT_REVISION::8}" ]; then
echo 'danger-swift updated.'
echo "value=true" >> $GITHUB_OUTPUT
fi
- name: Push image to DockerHub
if: ${{ github.event_name == 'workflow_dispatch' || steps.needs-update.outputs.value == 'true' }}
uses: docker/build-push-action@v5
with:
# Issue: It takes too much time on building arm64 image and failed to install Danger-Swift in GitHub Actions. https://github.com/417-72KI/danger-swiftlint/actions/runs/2453009152/jobs/3755764562
# platforms: ${{ (matrix.swift_version == 5.6 && 'linux/amd64,linux/arm64') || 'linux/amd64' }}
platforms: 'linux/amd64'
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.create-tags.outputs.tags }}
build-args: |
SWIFT_VERSION=${{ matrix.swift_version }}
SWIFT_LINT_REVISION=${{ steps.set-swiftlint-version.outputs.swiftlint-version }}
# - name: Update readme on DockerHub
# uses: wei/curl@v1
# with:
# args: -X POST ${{ secrets.DOCKER_HUB_TRIGGER_URL }}