-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (99 loc) · 3.94 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Create Releases and Build Docker images
on:
push:
branches:
- 'master'
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