-
-
Notifications
You must be signed in to change notification settings - Fork 589
129 lines (117 loc) · 4.42 KB
/
Copy pathtest-build.yml
File metadata and controls
129 lines (117 loc) · 4.42 KB
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
122
123
124
125
126
127
128
129
name: Build Experimental Docker Image
on:
pull_request:
types: [labeled]
workflow_dispatch:
inputs:
# trunk-ignore(checkov/CKV_GHA_7)
branch:
description: "Git branch"
required: true
registry:
description: "Container registry"
required: true
default: "ghcr"
type: choice
options:
- ghcr
- dockerhub
- both
permissions:
id-token: write
contents: write
packages: write
actions: write
pull-requests: write
jobs:
build:
if: |
github.event_name == 'workflow_dispatch' ||
contains(github.event.pull_request.labels.*.name, 'build-preview')
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
pull-requests: write
env:
USE_GHCR: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.registry == 'ghcr' || github.event.inputs.registry == 'both' }}
USE_DOCKERHUB: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.registry == 'dockerhub' || github.event.inputs.registry == 'both') }}
# Key the Docker Hub namespace off the push credential rather than the GitHub owner.
DOCKERHUB_NAMESPACE: ${{ secrets.DOCKER_NAMESPACE || secrets.DOCKER_USERNAME || github.repository_owner }}
steps:
- name: Run only once per workflow
run: echo "Triggered by ${{ github.event_name }}"
- name: Checkout code
uses: actions/checkout@v4.3.0
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.head_ref }}
fetch-depth: 0
- name: PR comment build starting
if: github.event_name == 'pull_request'
id: build-comment
uses: actions/github-script@v7
with:
script: |
const comment = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🔨 Preview build is under way...`
});
core.setOutput('comment-id', comment.data.id);
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.6.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.11.1
- name: Login to GHCR
if: env.USE_GHCR == 'true'
uses: docker/login-action@v3.5.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
if: env.USE_DOCKERHUB == 'true'
uses: docker/login-action@v3.5.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5.8.0
with:
images: |
${{ env.USE_GHCR == 'true' && format('name=ghcr.io/{0}/romm-testing', github.repository_owner) || '' }}
${{ env.USE_DOCKERHUB == 'true' && format('name={0}/romm-testing', env.DOCKERHUB_NAMESPACE) || '' }}
tags: |
type=raw,value=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.head_ref }}
- name: Build full image
id: build-full
uses: docker/build-push-action@v6.18.0
with:
file: docker/Dockerfile
context: .
push: true
platforms: linux/arm64,linux/amd64
tags: ${{ steps.meta.outputs.tags }}
target: full-image
build-args: |
SCREENSCRAPER_DEV_ID=${{ secrets.SCREENSCRAPER_DEV_ID }}
SCREENSCRAPER_DEV_PASSWORD=${{ secrets.SCREENSCRAPER_DEV_PASSWORD }}
# PR builds always push to GHCR only, so the image link is hardcoded to GHCR.
- name: Comment PR with GHCR image link
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
HEAD_REF: ${{ github.head_ref }}
with:
script: |
const owner = context.repo.owner;
const tag = process.env.HEAD_REF;
github.rest.issues.updateComment({
comment_id: ${{ steps.build-comment.outputs.comment-id }},
owner: owner,
repo: context.repo.repo,
body: `✅ Preview build completed!\n\nDocker image: \`ghcr.io/${owner}/romm-testing:${tag}\``
})