Skip to content

Commit 4b02871

Browse files
authored
Extend release pipeline to publish to APT repo (#102)
* Extend release pipeline to publish to APT repo * Set necessary AWS credentials environment variables * Remove duplicated comment in script * Clarify dist/ folder * Skip publishing to APT if tag contains a dash - * Restrict release workflow trigger to semantic version tags
1 parent e0d0555 commit 4b02871

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

.aptly.conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"rootDir": "./.aptly",
3+
"downloadConcurrency": 4,
4+
"downloadSpeedLimit": 0,
5+
"downloadRetries": 0,
6+
"downloader": "default",
7+
"databaseOpenAttempts": -1,
8+
"architectures": [],
9+
"dependencyFollowSuggests": false,
10+
"dependencyFollowRecommends": false,
11+
"dependencyFollowAllVariants": false,
12+
"dependencyFollowSource": false,
13+
"dependencyVerboseResolve": false,
14+
"gpgDisableSign": false,
15+
"gpgDisableVerify": false,
16+
"gpgProvider": "gpg",
17+
"downloadSourcePackages": false,
18+
"skipLegacyPool": true,
19+
"ppaDistributorID": "ubuntu",
20+
"ppaCodename": "",
21+
"skipContentsPublishing": false,
22+
"skipBz2Publishing": false,
23+
"FileSystemPublishEndpoints": {},
24+
"S3PublishEndpoints": {
25+
"stackit-cli-apt": {
26+
"region": "eu01",
27+
"bucket": "stackit-cli-apt",
28+
"acl":"public-read",
29+
"endpoint": "object.storage.eu01.onstackit.cloud"
30+
}
31+
},
32+
"SwiftPublishEndpoints": {},
33+
"AzurePublishEndpoints": {},
34+
"AsyncAPI": false,
35+
"enableMetricsEndpoint": false
36+
}

.github/workflows/release.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ name: Release
66
on:
77
push:
88
tags:
9-
- "v*"
9+
- "v[0-9]+.[0-9]+.[0-9]+"
10+
- "v[0-9]+.[0-9]+.[0-9]+-*"
1011
workflow_dispatch:
1112

1213
# Releases need permissions to read and write the repository contents.
@@ -19,6 +20,9 @@ jobs:
1920
runs-on: macOS-latest
2021
env:
2122
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
23+
# Needed to publish new packages to our S3-hosted APT repo
24+
AWS_ACCESS_KEY_ID: ${{ secrets.OBJECT_STORAGE_ACCESS_KEY_ID }}
25+
AWS_SECRET_ACCESS_KEY: ${{ secrets.OBJECT_STORAGE_SECRET_ACCESS_KEY }}
2226
steps:
2327
- uses: actions/checkout@v4
2428
with:
@@ -52,6 +56,8 @@ jobs:
5256
APPLE_KEY_ID: ${{ secrets.APPLE_KEY_ID }}
5357
SIGNING_CERTIFICATE_BASE64: ${{ secrets.APPLICATION_ID_CERT }}
5458
AUTHKEY_BASE64: ${{ secrets.APPLE_API_KEY }}
59+
- name: Install Aptly
60+
run: brew install aptly
5561
- name: Install Snapcraft
5662
uses: samuelmeuli/action-snapcraft@v2
5763
- name: Run GoReleaser
@@ -61,3 +67,9 @@ jobs:
6167
env:
6268
GITHUB_TOKEN: ${{ secrets.CLI_RELEASE }}
6369
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
70+
- name: Publish packages to APT repo
71+
if: ! contains(github.ref_name, '-')
72+
env:
73+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
74+
GPG_PRIVATE_KEY_ID: ${{ steps.import_gpg.outputs.keyid }}
75+
run: ./scripts/publish-apt-packages.sh

scripts/publish-apt-packages.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# This script is used to publish new packages to the CLI APT repository
4+
# Usage: ./publish-apt-packages.sh
5+
set -eo pipefail
6+
7+
ROOT_DIR=$(git rev-parse --show-toplevel)
8+
9+
OBJECT_STORAGE_ENDPOINT="https://object.storage.eu01.onstackit.cloud"
10+
APT_BUCKET_NAME="stackit-cli-apt"
11+
PUBLIC_KEY_BUCKET_NAME="stackit-public-key"
12+
PUBLIC_KEY_FILE="key.gpg"
13+
CUSTOM_KEYRING="custom-keyring"
14+
APTLY_CONFIG_FILE_PATH="./.aptly.conf"
15+
GORELEASER_PACKAGES_FOLDER="dist/"
16+
17+
# Create a local mirror of the current state of the remote APT repository
18+
printf ">>> Creating mirror \n"
19+
curl ${OBJECT_STORAGE_ENDPOINT}/${PUBLIC_KEY_BUCKET_NAME}/${PUBLIC_KEY_FILE} >public.asc
20+
gpg --no-default-keyring --keyring ./${CUSTOM_KEYRING}.gpg --import public.asc
21+
aptly mirror create -keyring="${CUSTOM_KEYRING}.gpg" current "${OBJECT_STORAGE_ENDPOINT}/${APT_BUCKET_NAME}" stackit
22+
23+
# Update the mirror to the latest state
24+
printf "\n>>> Updating mirror \n"
25+
aptly mirror update current
26+
27+
# Create a snapshot of the mirror
28+
printf "\n>>> Creating snapshop from mirror \n"
29+
aptly snapshot create current-snapshot from mirror current
30+
31+
# Create a new fresh local APT repo
32+
printf "\n>>> Creating fresh local repo \n"
33+
aptly repo create -distribution="stackit-cli" new-repo
34+
35+
# Add new generated .deb packages to the new local repo
36+
printf "\n>>> Adding new packages to local repo \n"
37+
aptly repo add new-repo ${GORELEASER_PACKAGES_FOLDER}
38+
39+
# Create a snapshot of the local repo
40+
printf "\n>>> Creating snapshot of local repo \n"
41+
aptly snapshot create new-snapshot from repo new-repo
42+
43+
# Merge new-snapshot into current-snapshot creating a new snapshot updated-snapshot
44+
printf "\n>>> Merging snapshots \n"
45+
aptly snapshot pull -no-remove -architectures="amd64,i386,arm64" current-snapshot new-snapshot updated-snapshot stackit
46+
47+
# Publish the new snapshot to the remote repo
48+
printf "\n>>> Publishing updated snapshot \n"
49+
aptly publish switch -gpg-key="${GPG_PRIVATE_KEY_ID}" -passphrase "${GPG_PASSPHRASE}" -config "${APTLY_CONFIG_FILE_PATH}" stackit "s3:${APT_BUCKET_NAME}:" updated-snapshot

0 commit comments

Comments
 (0)