-
Notifications
You must be signed in to change notification settings - Fork 54
121 lines (116 loc) · 3.83 KB
/
pull-request-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
118
119
120
121
name: Pull Request publish
on:
issue_comment:
types: [created]
env:
# TODO: Change variable to your image's name.
IMAGE_NAME: thomx/fr24feed-piaware
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
is_deploy_comment:
outputs:
is_deploy: ${{ steps.check.outputs.triggered }}
# Ensure test job passes before pushing image.
runs-on: ubuntu-latest
if: github.event.issue.pull_request
steps:
- name: If deploy comment
env:
COMMENT: ${{ github.event.comment.body }}
id: check
run: |
if [[ "${COMMENT}" == "@deploy" ]]; then
echo "Proceeding..."
echo "triggered=true" >> $GITHUB_OUTPUT
else
echo "triggered=false" >> $GITHUB_OUTPUT
curl -f -s -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel
sleep 60s
exit 42
fi
test:
needs: is_deploy_comment
if: needs.is_deploy_comment.outputs.is_deploy == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: 'refs/pull/${{ github.event.issue.number }}/merge'
- name: Get commit
id: get_commit
run: |
echo "sha_short=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: all-buildx-${{ steps.get_commit.outputs.sha_short }}
restore-keys: |
all-buildx-
- name: Build
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: false
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
# Push image to GitHub Packages and Docker Hub.
push:
# Ensure test job passes before pushing image.
needs: test
environment: docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: 'refs/pull/${{ github.event.issue.number }}/merge'
- name: Get commit
id: get_commit
run: |
echo "sha_short=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: all-buildx-${{ steps.get_commit.outputs.sha_short }}
restore-keys: |
all-buildx-
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get tags list
id: tags
run: |
TAGS=$IMAGE_NAME:PR-${{ github.event.issue.number }}
echo TAGS=$TAGS
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache