Skip to content
# This action will push version-tagged and latest images to Docker Hub
# This requires three secrets to be ste, the first two should be stored in Organization
# Secrets, the last is a per-repository secret.
# DOCKER_HUB_USERNAME: The Docker Hub username
# DOCKER_HUB_ACCESS_TOKEN: Instead of a password
# DOCKER_REPO_NAME: The full image name as it appears on Docker Hub
name: GitHub Release & Push to Docker Hub
on:
push:
tags: ["v*"]
jobs:
Deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Set up REPO and TAG environment vars
run: |
echo "REPO=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
echo "TAG=${GITHUB_SHA:0:6}" >> $GITHUB_ENV
- name: This run was triggered by a version tag, reset the $TAG variable to the tag name
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Read latest WordPress version from wp-version.json
run: |
echo "WP_VERSION=$(jq -r '.wordpress' wp-version.json)" >> $GITHUB_ENV
- name: Create GitHub release
if: ${{ contains(github.ref, 'refs/tags/') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${TAG}
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
# https://github.com/docker/login-action
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# https://github.com/docker/metadata-action
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ secrets.DOCKER_REPO_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,${{ env.WP_VERSION }}-${{ env.TAG }}
type=raw,${{ env.WP_VERSION }}
# https://github.com/docker/build-push-action
- name: Build and push to DockerHub
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}