-
Notifications
You must be signed in to change notification settings - Fork 25
68 lines (59 loc) · 2.24 KB
/
docker-build-cmd.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
# .github/workflows/docker-build-on-comment.yml
# This will only compile x86_64 docker images, NO CROSS-COMPILE!
# NOTE: to make this work, this repository needs write access to the specific containers:
# - bolt-sidecar
# - bolt-boost
# You can configure this in the package settings under Manage Actions access. Make sure to set "role" to "write".
name: Build Docker Image on Comment
on:
issue_comment:
types: [created]
permissions:
contents: read
pull-requests: write
packages: write
jobs:
build:
if: |
github.event.issue.pull_request != null &&
startsWith(github.event.comment.body, '/build ') &&
github.event.comment.author_association == 'COLLABORATOR'
runs-on: self-hosted
steps:
- name: Extract subdirectory and tag from comment
id: extract
run: |
clean_comment=$(echo "${{ github.event.comment.body }}" | tr -d '\r' | xargs)
echo "Comment: $clean_comment"
if [[ "$clean_comment" =~ ^/build[[:space:]]+([^:]+):(.+)$ ]]; then
echo "subdir=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "tag=${BASH_REMATCH[2]}" >> $GITHUB_ENV
else
echo "Comment does not match the expected pattern."
exit 1
fi
- name: Checkout PR code
uses: actions/checkout@v4
with:
ref: ${{ github.event.issue.pull_request.head.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./${{ env.subdir }}
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ env.subdir }}:${{ env.tag }}
- name: Post comment on PR
uses: thollander/actions-comment-pull-request@v1
with:
message: |
The Docker image has been successfully built and pushed to GHCR.
Image: `ghcr.io/${{ github.repository_owner }}/${{ env.subdir }}:${{ env.tag }}`
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}