-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (133 loc) · 4.65 KB
/
Copy pathdocker-build.yml
File metadata and controls
152 lines (133 loc) · 4.65 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Build and Push Docker Image
env:
DOCKERHUB_USER: devopsiaci
DOCKERHUB_REPO: pr-generator
GHCR_REGISTRY: ghcr.io
GHCR_REPO: ${{ github.repository }}
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.13"
cache: pip
cache-dependency-path: requirements.txt
- name: Install dependencies
run: pip install -r requirements.txt pytest
- name: Run tests
run: python -m pytest tests/ -v
release:
name: Release
needs: [test]
# Only run on direct pushes to main (not on pull requests)
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
attestations: write
contents: write
id-token: write
issues: write
packages: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v6
with:
tag_format: 'v${version}'
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Docker metadata
id: meta
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/metadata-action@v6
with:
images: |
${{ env.DOCKERHUB_USER }}/${{ env.DOCKERHUB_REPO }}
${{ env.GHCR_REGISTRY }}/${{ env.GHCR_REPO }}
labels: |
org.opencontainers.image.maintainer=amartingarcia,ialejandro'
org.opencontainers.image.title='PR Generator'
org.opencontainers.image.description='PR Generator to automate pull request management'
org.opencontainers.image.vendor='devops-ia'
tags: |
type=raw,value=${{ steps.semantic.outputs.new_release_git_tag }}
- name: Set up QEMU
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/setup-buildx-action@v4
- name: Cache Docker layers
if: steps.semantic.outputs.new_release_published == 'true'
uses: actions/cache@v5
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: "[DOCKERHUB] Log in"
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: "[GHCR] Log in"
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/login-action@v4
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
id: push
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/build-push-action@v7
with:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
context: .
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: true
sbom: true
tags: ${{ steps.meta.outputs.tags }}
- name: "[DOCKERHUB] Update registry description"
if: steps.semantic.outputs.new_release_published == 'true'
uses: peter-evans/dockerhub-description@v5
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.DOCKERHUB_USER }}/${{ env.DOCKERHUB_REPO }}
- name: "[GHCR] Generate artifact attestation"
if: steps.semantic.outputs.new_release_published == 'true'
uses: actions/attest-build-provenance@v4
with:
subject-name: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_REPO }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Move Docker cache
if: steps.semantic.outputs.new_release_published == 'true'
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache