Skip to content

Commit 6a27512

Browse files
authored
Merge pull request #23 from wayofdev/feat/refactor
feat: move to reusable workflow
2 parents 5bfe1ee + 772e4c9 commit 6a27512

File tree

2 files changed

+54
-151
lines changed

2 files changed

+54
-151
lines changed

.github/workflows/build-latest.yml

Lines changed: 24 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -12,83 +12,33 @@ on: # yamllint disable-line rule:truthy
1212
name: 🚀 Build docker images with latest tag
1313

1414
jobs:
15-
build:
15+
# https://docs.github.com/en/enterprise-cloud@latest/actions/learn-github-actions/expressions#example-returning-a-json-object
16+
prepare:
1617
runs-on: "ubuntu-latest"
17-
strategy:
18-
fail-fast: true
19-
matrix:
20-
os_name: ["alpine"]
21-
php_version: ["8.1"]
22-
php_type: ["fpm"]
23-
# php_version: ["8.1", "8.2"]
24-
# php_type: ["fpm", "cli", "supervisord"]
25-
environment:
26-
name: latest
27-
url: https://hub.docker.com/r/wayofdev/php-base/tags?page=1&name=latest
28-
18+
outputs:
19+
matrix: ${{ steps.matrix.outputs.matrix }}
2920
steps:
30-
- name: 📦 Check out the codebase
31-
uses: actions/checkout@v3
32-
33-
- name: 🛠️ Install goss and dgoss
34-
uses: e1himself/[email protected]
35-
36-
- name: 🌎 Set environment variables
37-
env:
38-
IMAGE_NAMESPACE: wayofdev/php-base
39-
IMAGE_TEMPLATE: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}
40-
IMAGE_TAG: wayofdev/php-base:${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}-latest
21+
- id: matrix
4122
run: |
42-
echo "IMAGE_NAMESPACE=${IMAGE_NAMESPACE}" >> $GITHUB_ENV
43-
echo "IMAGE_TEMPLATE=${IMAGE_TEMPLATE}" >> $GITHUB_ENV
44-
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
45-
46-
- name: 🤖 Generate dist files
47-
run: make generate
48-
49-
- name: 🐳 Extract docker meta data
50-
id: meta
51-
uses: docker/metadata-action@v4
52-
with:
53-
images: ${{ env.IMAGE_NAMESPACE }}
54-
tags: |
55-
type=raw,event=branch,value=latest
56-
type=ref,event=pr
57-
type=semver,pattern={{version}}
58-
type=semver,pattern={{major}}.{{minor}}
59-
flavor: |
60-
latest=false
61-
prefix=${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}-
23+
echo 'matrix={
24+
"os_name": ["alpine"],
25+
"php_version": ["8.1", "8.2"],
26+
"php_type": ["fpm", "cli", "supervisord"]
27+
}' | tr -d '\n' >> $GITHUB_OUTPUT
6228
63-
- name: 🔑 Login to docker-hub
64-
if: github.event_name != 'pull_request'
65-
uses: docker/login-action@v2
66-
with:
67-
username: ${{ secrets.DOCKER_USERNAME }}
68-
password: ${{ secrets.DOCKER_TOKEN }}
69-
70-
- name: 🖥️ Setup QEMU
71-
uses: docker/setup-qemu-action@v2
72-
with:
73-
platforms: arm64
74-
75-
- name: 🛠️ Setup docker Buildx
76-
uses: docker/setup-buildx-action@v2
77-
with:
78-
install: true
79-
80-
- name: 🚀 Build image and push to docker-hub
81-
uses: docker/build-push-action@v4
82-
with:
83-
context: ./dist/base/${{ env.IMAGE_TEMPLATE }}
84-
platforms: linux/amd64,linux/arm64
85-
push: ${{ github.event_name != 'pull_request' }}
86-
tags: ${{ steps.meta.outputs.tags }}
87-
cache-from: type=gha
88-
cache-to: type=gha,mode=max
89-
labels: ${{ steps.meta.outputs.labels }}
90-
91-
- name: 🧪 Test Docker image with "latest" tag
92-
run: IMAGE_TAG=${{ env.IMAGE_TAG }} make test
29+
build:
30+
needs: prepare
31+
strategy:
32+
matrix: ${{ fromJson(needs.prepare.outputs.matrix )}}
33+
uses: wayofdev/gh-actions/.github/workflows/build-image.yml@master
34+
with:
35+
os: "ubuntu-latest"
36+
push-to-hub: ${{ github.event_name != 'pull_request' }}
37+
image-namespace: "wayofdev/php-base"
38+
image-template: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}
39+
image-version: latest
40+
secrets:
41+
docker-username: ${{ secrets.DOCKER_USERNAME }}
42+
docker-password: ${{ secrets.DOCKER_TOKEN }}
9343

9444
...

.github/workflows/build-release.yml

Lines changed: 30 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,86 +8,39 @@ on: # yamllint disable-line rule:truthy
88
name: 🚀 Build docker images with release tag
99

1010
jobs:
11-
build:
11+
# https://docs.github.com/en/enterprise-cloud@latest/actions/learn-github-actions/expressions#example-returning-a-json-object
12+
prepare:
1213
runs-on: "ubuntu-latest"
13-
strategy:
14-
fail-fast: true
15-
matrix:
16-
os_name: ["alpine"]
17-
php_version: [ "8.1" ]
18-
php_type: [ "fpm" ]
19-
# php_version: ["8.1", "8.2"]
20-
# php_type: ["fpm", "cli", "supervisord"]
21-
environment:
22-
name: release
23-
url: https://hub.docker.com/r/wayofdev/php-base/tags?page=1
24-
14+
outputs:
15+
matrix: ${{ steps.matrix.outputs.matrix }}
2516
steps:
26-
- name: 📦 Check out the codebase
27-
uses: actions/checkout@v3
28-
29-
- name: 🛠️ Install goss and dgoss
30-
uses: e1himself/[email protected]
31-
32-
- name: 🌎 Set environment variables
33-
env:
34-
IMAGE_NAMESPACE: wayofdev/php-base
35-
IMAGE_TEMPLATE: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}
36-
IMAGE_TAG: wayofdev/php-base:${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}-${{ env.VERSION }}
17+
- name: ⚙️ Generate matrix
18+
id: matrix
3719
run: |
38-
export RELEASE_VERSION="${GITHUB_REF#refs/*/}" \
39-
&& { \
40-
echo "IMAGE_NAMESPACE=${IMAGE_NAMESPACE}"; \
41-
echo "IMAGE_TEMPLATE=${IMAGE_TEMPLATE}"; \
42-
echo "VERSION=${RELEASE_VERSION:1}"; \
43-
} >> "$GITHUB_ENV"
44-
45-
- name: 🤖 Generate dist files
46-
run: make generate
47-
48-
- name: 🐳 Extract docker meta data
49-
id: meta
50-
uses: docker/metadata-action@v4
51-
with:
52-
images: ${{ env.IMAGE_NAMESPACE }}
53-
tags: |
54-
type=raw,event=branch,value=latest
55-
type=ref,event=pr
56-
type=semver,pattern={{version}}
57-
type=semver,pattern={{major}}.{{minor}}
58-
flavor: |
59-
latest=false
60-
prefix=${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}-
61-
62-
- name: 🔑 Login to docker-hub
63-
if: github.event_name != 'pull_request'
64-
uses: docker/login-action@v2
65-
with:
66-
username: ${{ secrets.DOCKER_USERNAME }}
67-
password: ${{ secrets.DOCKER_TOKEN }}
68-
69-
- name: 🖥️ Setup QEMU
70-
uses: docker/setup-qemu-action@v2
71-
with:
72-
platforms: arm64
73-
74-
- name: 🛠️ Setup docker Buildx
75-
uses: docker/setup-buildx-action@v2
76-
with:
77-
install: true
78-
79-
- name: 🚀 Build image and push to docker-hub
80-
uses: docker/build-push-action@v4
81-
with:
82-
context: ./dist/base/${{ env.IMAGE_TEMPLATE }}
83-
platforms: linux/amd64,linux/arm64
84-
push: ${{ github.event_name != 'pull_request' }}
85-
tags: ${{ steps.meta.outputs.tags }}
86-
cache-from: type=gha
87-
cache-to: type=gha,mode=max
88-
labels: ${{ steps.meta.outputs.labels }}
20+
echo 'matrix={
21+
"os_name": ["alpine"],
22+
"php_version": ["8.1", "8.2"],
23+
"php_type": ["fpm", "cli", "supervisord"]
24+
}' | tr -d '\n' >> $GITHUB_OUTPUT
25+
26+
- name: ⚙️ Get version for image tag
27+
id: version
28+
run: |
29+
echo "version=$(echo ${GITHUB_REF#refs/*/} | cut -c 2-)" >> $GITHUB_OUTPUT
8930
90-
- name: 🧪 Test Docker image with "version" tag
91-
run: IMAGE_TAG=${{ env.IMAGE_TAG }} make test
31+
build:
32+
needs: prepare
33+
strategy:
34+
matrix: ${{ fromJson(needs.prepare.outputs.matrix )}}
35+
uses: wayofdev/gh-actions/.github/workflows/build-image.yml@master
36+
with:
37+
os: "ubuntu-latest"
38+
push-to-hub: true
39+
image-namespace: "wayofdev/php-base"
40+
image-template: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}
41+
image-version: ${{ needs.prepare.outputs.version }}
42+
secrets:
43+
docker-username: ${{ secrets.DOCKER_USERNAME }}
44+
docker-password: ${{ secrets.DOCKER_TOKEN }}
9245

9346
...

0 commit comments

Comments
 (0)