-
Notifications
You must be signed in to change notification settings - Fork 14
198 lines (166 loc) · 6.66 KB
/
syslog-ng-snapshot.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: syslog-ng snapshot
on:
workflow_dispatch:
inputs:
repo:
description: 'syslog-ng repository'
required: true
default: 'syslog-ng/syslog-ng'
type: string
ref:
description: 'syslog-ng ref (branch, tag, commit id)'
required: true
default: 'master'
type: string
pull_request:
paths:
- 'syslog-ng/**'
- '.github/workflows/**'
push:
paths:
- 'syslog-ng/**'
- '.github/workflows/**'
schedule:
- cron: '00 23 * * *'
jobs:
tarball:
name: create-source-tarball
runs-on: ubuntu-latest
outputs:
snapshot-version: ${{ steps.snapshot-version.outputs.SNAPSHOT_VERSION }}
steps:
- name: Checkout syslog-ng source
uses: actions/checkout@v4
with:
repository: ${{ inputs.repo || 'syslog-ng/syslog-ng' }}
ref: ${{ inputs.ref || 'master' }}
fetch-depth: 0
- name: Prepare docker image
run: ./dbld/rules cache-image-tarball
- name: Create source tarball
run: ./dbld/rules pkg-tarball
- name: Determine snapshot version
id: snapshot-version
run: |
tarball_filename="$(find dbld/build -name '*.tar.*' -printf '%f\n')"
tarball_name="${tarball_filename/\.tar.*}"
tarball_version="${tarball_name/syslog-ng-}"
pkg_version="$(echo $tarball_version | sed -E 's|(([0-9]+\.){2}[0-9]+).*|\1|')_git$(date +%Y%m%d)"
echo "SNAPSHOT_VERSION=${pkg_version}" >> $GITHUB_OUTPUT
- name: Store source tarball as artifact
uses: actions/upload-artifact@v4
with:
name: source-tarball
path: dbld/build/*.tar.*
axosyslog-modules:
name: axosyslog-modules
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Create AxoSyslog modules tarball
working-directory: syslog-ng
run: |
tar -czvf python-modules.tar.gz python-modules/
- name: Store axosyslog-modules tarball as artifact
uses: actions/upload-artifact@v4
with:
name: axosyslog-modules-tarball
path: syslog-ng/python-modules.tar.gz
build-and-test:
runs-on: ubuntu-latest
needs:
- tarball
- axosyslog-modules
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Download source tarball artifact
uses: actions/download-artifact@v4
with:
name: source-tarball
path: syslog-ng/apkbuild/axoflow/syslog-ng
- name: Download axosyslog-modules tarball artifact
uses: actions/download-artifact@v4
with:
name: axosyslog-modules-tarball
path: syslog-ng/apkbuild/axoflow/syslog-ng
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: syslog-ng
file: syslog-ng/alpine.dockerfile
load: true
tags: syslog-ng:test
build-args: |
PKG_TYPE=nightly
SNAPSHOT_VERSION=${{ needs.tarball.outputs.snapshot-version }}
- name: Smoke test
run: |
export SYSLOG_NG_IMAGE="syslog-ng:test"
export SYSLOG_NG_VERSION="${{ needs.tarball.outputs.snapshot-version }}"
syslog-ng/tests/smoke.sh
publish-image:
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/syslog-ng-docker.yml
needs: [tarball, build-and-test, axosyslog-modules]
with:
pkg-type: nightly
tarball-artifact: source-tarball
axosyslog-modules-artifact: axosyslog-modules-tarball
snapshot-version: ${{ needs.tarball.outputs.snapshot-version }}
# https://github.com/actions/delete-package-versions/issues/90
cleanup-old-images:
if: github.ref == 'refs/heads/main'
needs: publish-image
runs-on: ubuntu-latest
steps:
- name: Clean up old images
uses: actions/github-script@v7
with:
script: |
const daysToKeep = 30
const snapshotTagPattern = /_git[0-9]+/
const package_name = "axosyslog"
const org = "axoflow"
const image = `${org}/${package_name}`
const allPackageVersions = await github.paginate(
github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg,
{ package_type: "container", package_name: package_name, org: org }
)
const oldPackageDate = new Date()
oldPackageDate.setDate(oldPackageDate.getDate() - daysToKeep)
const oldSnapshotVersions = allPackageVersions.filter((p) => {
return new Date(p.updated_at) < oldPackageDate && p.metadata.container && p.metadata.container.tags.length != 0 && p.metadata.container.tags.every((t) => snapshotTagPattern.test(t))
})
if (oldSnapshotVersions.length === 0) {
console.log("Nothing to remove")
return
}
const oldSnapshotTags = oldSnapshotVersions.flatMap(({ metadata }) => metadata.container.tags)
console.log(`Removing the following images: ${oldSnapshotTags}`)
const manifestsRequests = oldSnapshotTags.map((t) => {
const manifest = fetch(`https://ghcr.io/v2/${image}/manifests/${t}`, {
method: "GET",
headers: {
"Authorization": "Bearer ${{ secrets.GITHUB_TOKEN }}",
"Accept": "application/vnd.docker.distribution.manifest.list.v2+json",
"Accept": "application/vnd.docker.distribution.manifest.v2+json",
"Accept": "application/vnd.oci.image.manifest.v1+json",
"Accept": "application/vnd.oci.image.index.v1+json",
},
}).then((d) => d.json())
return manifest
})
const manifestsResponse = await Promise.all(manifestsRequests)
const manifestsToDelete = manifestsResponse.filter((m) => m.manifests).flatMap((m) => m.manifests)
await Promise.all(manifestsToDelete.map((m) => {
const version = allPackageVersions.find((p) => p.name === m.digest)
if (!version) {
return;
}
return github.rest.packages.deletePackageVersionForOrg({ package_type: "container", package_name: package_name, org: org, package_version_id: version.id})
}))
await Promise.all(oldSnapshotVersions.map((v) => {
return github.rest.packages.deletePackageVersionForOrg({ package_type: "container", package_name: package_name, org: org, package_version_id: v.id})
}))