generated from actions/container-action
-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (116 loc) · 3.77 KB
/
cd.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
122
123
124
125
126
127
128
129
130
131
132
133
# When a PR is merged, or when run manually, this workflow will create a
# release and publish the container image to the GitHub Container Registry. Both
# will be labeled with the version specified in the manifest file.
name: Continuous Delivery
on:
pull_request:
types:
- closed
branches:
- main
workflow_dispatch:
env:
CONTAINER_REGISTRY: ghcr.io
CONTAINER_REGISTRY_USERNAME: danielgospodinow
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.GH_DANIELGOSPODINOW_PACKAGES_ACCESS_TOKEN }}
MANIFEST_PATH: .version
permissions:
contents: write
packages: write
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
# Ignore Dependabot pull requests.
if: |
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true &&
github.event.pull_request.user.login != 'dependabot[bot]')
outputs:
# Semantic version to use for tagging container images.
# E.g. `1.2.3` or `1.2.3-alpha.4`
version: ${{ steps.tag.outputs.version }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-tags: true
ref: main
- name: Tag Version
id: tag
uses: issue-ops/[email protected]
with:
manifest-path: ${{ env.MANIFEST_PATH }}
ref: main
workspace: ${{ github.workspace }}
- name: Create Release
id: release
uses: issue-ops/[email protected]
with:
tag: v${{ steps.tag.outputs.version }}
publish:
name: Publish Container Image
runs-on: ubuntu-latest
needs: release
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-tags: true
ref: main
# Create the list of image tags that will be published. If a prerelease is
# being published (e.g. `1.2.3-alpha.4`), only the prerelease tag will be
# published (`v1.2.3-alpha.4`). Otherwise, the following tags will be
# published:
# - `latest`
# - `v1.2.3`
# - `v1.2`
# - `v1`
- name: Set Image Tags
id: tags
uses: actions/github-script@v7
with:
script: |
const version = '${{ needs.release.outputs.version }}'
// Check if prerelease (e.g. 1.2.3-alpha.4)
if (version.includes('-')) {
// Only output the prerelease tag
core.setOutput('tags', `type=raw,value=v${version}`)
} else {
// Output all the tags
let tags = [
'type=raw,value=latest',
`type=raw,value=v${version}`,
`type=raw,value=v${version.split('.').slice(0, 2).join('.')}`,
`type=raw,value=v${version.split('.')[0]}`
]
core.setOutput('tags', tags.join('\n'))
}
# Get metadata to apply to image
- name: Extract Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.CONTAINER_REGISTRY }}/${{ github.repository }}
tags: ${{ steps.tags.outputs.tags }}
# Authenticate to the container registry
- name: Authenticate to Container Registry
id: login
uses: docker/login-action@v3
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ env.CONTAINER_REGISTRY_USERNAME }}
password: ${{ env.CONTAINER_REGISTRY_PASSWORD }}
# Publish the container image
- name: Publish Container Image
id: publish
uses: docker/build-push-action@v6
env:
LABELS: ${{ steps.meta.outputs.labels }}
TAGS: ${{ steps.meta.outputs.tags }}
with:
labels: ${{ env.LABELS }}
push: true
tags: ${{ env.TAGS }}