Repository navigation
75 lines (64 loc) · 2.26 KB
/
Copy pathpush-pr-image.yaml
File metadata and controls
75 lines (64 loc) · 2.26 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
name: Push PR Image on Label
# Use pull_request_target to run in base repo context (has secrets access)
# This is safe because we only run after maintainer adds the label (implicit code review)
on:
pull_request_target:
branches:
- master
types: [ labeled ]
env:
REGISTRY: ghcr.io
permissions:
contents: read
packages: write
jobs:
push-image:
runs-on: ubuntu-latest
name: Push PR Image
if: ${{ github.event.label.name == 'build-push-image' }}
steps:
- name: Remove the build label
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: build-push-image
- name: Check out code
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Generate Tag
id: generate_tag
run: |
sha=${{ github.event.pull_request.head.sha }}
tag="SNAPSHOT-PR-${{ github.event.pull_request.number }}-${sha:0:8}"
echo "GIT_TAG=${tag}" >> $GITHUB_OUTPUT
- name: Generate build metadata
id: meta
run: |
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Generate image repository path
run: |
echo GHCR_IMAGE_REPOSITORY=${{ env.REGISTRY }}/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Login to ghcr registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: stakater-user
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push image
uses: docker/build-push-action@v7
with:
context: .
file: Dockerfile
pull: true
push: true
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.GHCR_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=${{ steps.meta.outputs.created }}
org.opencontainers.image.revision=${{ github.event.pull_request.head.sha }}