-
Notifications
You must be signed in to change notification settings - Fork 4
117 lines (102 loc) · 3.29 KB
/
docker-publish.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
112
113
114
115
116
117
name: Docker publish
on:
push:
branches:
- main
tags:
- wp*
schedule:
- cron: '0 4 * * 0'
env:
IMAGE_NAME: wordpress-xdebug
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker build -f Dockerfile .
tag:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.create-tag.outputs.tag }}
tag_exists: ${{ steps.check-tag.outputs.result }}
steps:
- uses: actions/checkout@v4
- name: Get dockerhub wordpress latest version tag
id: image-tag
uses: ./.github/actions/get-dockerhub-version-tag
with:
org: 'library'
repo: 'wordpress'
- name: Get Xdebug pecl package version
id: package-version
uses: ./.github/actions/get-pecl-package-version
with:
package: 'xdebug'
stability: 'stable'
- name: Create tag
id: create-tag
run: echo "tag=wp${{ steps.image-tag.outputs.tag}}-xdebug${{ steps.package-version.outputs.version }}" >> $GITHUB_OUTPUT
- name: Check if tag already exists
id: check-tag
uses: actions/github-script@v7
with:
script: |
let tag_exists = 0;
try {
await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "tags/${{ steps.create-tag.outputs.tag }}"
})
tag_exists = 1;
} catch(err) {
if (err.status != 404) throw err;
}
return tag_exists;
- name: Push tag
id: push-tag
if: steps.check-tag.outputs.result == 0
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ steps.create-tag.outputs.tag }}",
sha: context.sha
})
push:
environment: production
needs: [tag, test]
runs-on: ubuntu-latest
if: needs.tag.outputs.tag_exists == 0
steps:
- uses: actions/checkout@v4
- run: docker build -f Dockerfile -t $IMAGE_NAME .
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image
run: |
GH_IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME
DH_IMAGE_ID=${{ github.actor }}/$IMAGE_NAME
# Change all uppercase to lowercase
GH_IMAGE_ID=$(echo $GH_IMAGE_ID | tr '[A-Z]' '[a-z]')
DH_IMAGE_ID=$(echo $DH_IMAGE_ID | tr '[A-Z]' '[a-z]')
# Version from created tag
VERSION=${{ needs.tag.outputs.tag }}
docker tag $IMAGE_NAME $GH_IMAGE_ID:latest
docker tag $IMAGE_NAME $GH_IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $DH_IMAGE_ID:latest
docker tag $IMAGE_NAME $DH_IMAGE_ID:$VERSION
docker push --all-tags $GH_IMAGE_ID
docker push --all-tags $DH_IMAGE_ID