add manual dispather so we can build without code changes (ie: just n… #62
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 Releases and Build Docker images | |
on: | |
push: | |
branches: | |
- 'master' | |
# Allows us to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
create-release-and-build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] | |
type: ['cli', 'fpm'] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup GitHub CLI | |
run: | | |
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}" | |
- name: Create Releases | |
run: | | |
DIR=${{ matrix.type }}/${{ matrix.version }} | |
if [[ -f "$DIR/.env" ]]; then | |
set -a | |
source $DIR/.env | |
set +a | |
TAG_NAME="${PHP_VERSION}-${{ matrix.type }}" | |
DOCKER_HUB_LINK="https://hub.docker.com/r/mxmd/php/tags?page=1&name=${PHP_VERSION}-${{ matrix.type }}" | |
if ! gh release view $TAG_NAME > /dev/null 2>&1; then | |
# Create GH Release if it does not exist | |
gh release create $TAG_NAME \ | |
--title "PHP $PHP_VERSION (${{ matrix.type }}) release" \ | |
--notes "Release of Docker image for PHP $PHP_VERSION (${{ matrix.type }}). [View on Docker Hub]($DOCKER_HUB_LINK)" | |
echo "RELEASE_CREATED=true" >> $GITHUB_ENV | |
fi | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up environment variables | |
run: | | |
DIR=${{ matrix.type }}/${{ matrix.version }} | |
if [[ -f "$DIR/.env" ]]; then | |
set -a | |
source $DIR/.env | |
set +a | |
for VAR_NAME in PLATFORM PHP_VERSION PHP_VERSION_MAJOR ALPINE_VERSION; do | |
echo "$VAR_NAME=${!VAR_NAME}" >> $GITHUB_ENV | |
done | |
else | |
echo "No .env file found in $DIR" >&2 | |
exit 1 | |
fi | |
- name: Print environment variables for debugging | |
run: | | |
echo "PHP_VERSION: $PHP_VERSION" | |
echo "PHP_VERSION_MAJOR: $PHP_VERSION_MAJOR" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build Docker images | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./${{ matrix.type }} | |
push: false | |
platforms: linux/amd64,linux/arm64 | |
tags: | | |
mxmd/php:${{ env.PHP_VERSION }}-${{ matrix.type }} | |
mxmd/php:${{ env.PHP_VERSION_MAJOR }}-${{ matrix.type }} | |
build-args: | | |
PHP_VERSION=${{ env.PHP_VERSION }} | |
PHP_VERSION_MAJOR=${{ env.PHP_VERSION_MAJOR }} | |
ALPINE_VERSION=${{ env.ALPINE_VERSION }} | |
ALPINE_IMAGE=alpine:${{ env.ALPINE_VERSION }} | |
file: ${{ matrix.type }}/${{ matrix.version }}/Dockerfile | |
- name: Generate build timestamp | |
id: build-timestamp | |
run: echo "BUILD_TIMESTAMP=$(date +'%Y%m%d%H%M')" >> $GITHUB_ENV | |
- name: Push Docker images | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./${{ matrix.type }} | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: | | |
mxmd/php:${{ env.PHP_VERSION }}-${{ matrix.type }} | |
mxmd/php:${{ env.PHP_VERSION_MAJOR }}-${{ matrix.type }} | |
mxmd/php:${{ env.PHP_VERSION }}-${{ matrix.type }}-${{ env.BUILD_TIMESTAMP }} | |
mxmd/php:${{ env.PHP_VERSION_MAJOR }}-${{ matrix.type }}-${{ env.BUILD_TIMESTAMP }} | |
build-args: | | |
PHP_VERSION=${{ env.PHP_VERSION }} | |
PHP_VERSION_MAJOR=${{ env.PHP_VERSION_MAJOR }} | |
ALPINE_VERSION=${{ env.ALPINE_VERSION }} | |
ALPINE_IMAGE=alpine:${{ env.ALPINE_VERSION }} | |
file: ${{ matrix.type }}/${{ matrix.version }}/Dockerfile |