Skip to content

Commit f88a136

Browse files
authored
Merge pull request #2076 from smallstep/jdoss/repos
Configure GitHub Actions to publish RPMs and Debs to packages.smallstep.com
2 parents 7c9e3ff + 354af7f commit f88a136

File tree

5 files changed

+125
-4
lines changed

5 files changed

+125
-4
lines changed

.github/workflows/release.yml

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
contents: write
6262
packages: write
6363
uses: smallstep/workflows/.github/workflows/goreleaser.yml@main
64+
with:
65+
enable-packages-upload: true
66+
is-prerelease: ${{ needs.create_release.outputs.is_prerelease == 'true' }}
6467
secrets: inherit
6568

6669
build_upload_docker:

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ go.work.sum
2222
coverage.txt
2323
output
2424
vendor
25+
dist/
2526
.idea
2627
.envrc
28+
29+
# Packages files
30+
0x889B19391F774443-Certify.key
31+
gha-creds-*.json

.goreleaser.yml

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
# Documentation: https://goreleaser.com/customization/
2+
# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json
23
project_name: step-ca
34
version: 2
45

6+
variables:
7+
packageName: step-ca
8+
packageRelease: 1 # Manually update release: in the nfpm section to match this value if you change this
9+
510
before:
611
hooks:
712
# You may remove this if you don't use go modules.
813
- go mod download
914

15+
after:
16+
hooks:
17+
# This script depends on IS_PRERELEASE env being set. This is set by CI in the Is Pre-release step.
18+
- cmd: bash scripts/package-repo-import.sh {{ .Var.packageName }} {{ .Version }}
19+
output: true
20+
1021
builds:
1122
-
1223
id: step-ca
@@ -61,10 +72,16 @@ nfpms:
6172
# Package metadata: dpkg --info dist/step_....deb
6273
#
6374
- &NFPM
75+
id: packages
6476
builds:
6577
- step-ca
66-
package_name: step-ca
67-
file_name_template: "{{ .PackageName }}_{{ .Version }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
78+
package_name: "{{ .Var.packageName }}"
79+
release: "1"
80+
file_name_template: >-
81+
{{- trimsuffix .ConventionalFileName .ConventionalExtension -}}
82+
{{- if and (eq .Arm "6") (eq .ConventionalExtension ".deb") }}6{{ end -}}
83+
{{- if not (eq .Amd64 "v1")}}{{ .Amd64 }}{{ end -}}
84+
{{- .ConventionalExtension -}}
6885
vendor: Smallstep Labs
6986
homepage: https://github.com/smallstep/certificates
7087
maintainer: Smallstep <[email protected]>
@@ -80,6 +97,13 @@ nfpms:
8097
contents:
8198
- src: debian/copyright
8299
dst: /usr/share/doc/step-ca/copyright
100+
rpm:
101+
signature:
102+
key_file: "{{ .Env.GPG_PRIVATE_KEY_FILE }}"
103+
deb:
104+
signature:
105+
key_file: "{{ .Env.GPG_PRIVATE_KEY_FILE }}"
106+
type: origin
83107
-
84108
<< : *NFPM
85109
id: unversioned
@@ -101,6 +125,12 @@ signs:
101125
args: ["sign-blob", "--oidc-issuer=https://token.actions.githubusercontent.com", "--output-certificate=${certificate}", "--output-signature=${signature}", "${artifact}", "--yes"]
102126
artifacts: all
103127

128+
publishers:
129+
- name: Google Cloud Artifact Registry
130+
ids:
131+
- packages
132+
cmd: ./scripts/package-upload.sh {{ abs .ArtifactPath }} {{ .Var.packageName }} {{ .Version }} {{ .Var.packageRelease }}
133+
104134
snapshot:
105135
name_template: "{{ .Tag }}-next"
106136

@@ -140,7 +170,10 @@ release:
140170
#### Linux
141171
142172
- 📦 [step-ca_linux_{{ .Version }}_amd64.tar.gz](https://dl.smallstep.com/gh-release/certificates/gh-release-header/{{ .Tag }}/step-ca_linux_{{ .Version }}_amd64.tar.gz)
143-
- 📦 [step-ca_{{ .Version }}_amd64.deb](https://dl.smallstep.com/gh-release/certificates/gh-release-header/{{ .Tag }}/step-ca_{{ .Version }}_amd64.deb)
173+
- 📦 [step-ca_{{ replace .Version "-" "." }}-{{ .Var.packageRelease }}_amd64.deb](https://dl.smallstep.com/gh-release/cli/gh-release-header/{{ .Tag }}/step-ca_{{ replace .Version "-" "." }}-{{ .Var.packageRelease }}_amd64.deb)
174+
- 📦 [step-ca-{{ replace .Version "-" "." }}-{{ .Var.packageRelease }}.x86_64.rpm](https://dl.smallstep.com/gh-release/cli/gh-release-header/{{ .Tag }}/step-ca-{{ replace .Version "-" "." }}-{{ .Var.packageRelease }}.x86_64.rpm)
175+
- 📦 [step-ca_{{ replace .Version "-" "." }}-{{ .Var.packageRelease }}_arm64.deb](https://dl.smallstep.com/gh-release/cli/gh-release-header/{{ .Tag }}/step-ca_{{ replace .Version "-" "." }}-{{ .Var.packageRelease }}_arm64.deb)
176+
- 📦 [step-ca-{{ replace .Version "-" "." }}-{{ .Var.packageRelease }}.aarch64.rpm](https://dl.smallstep.com/gh-release/cli/gh-release-header/{{ .Tag }}/step-ca-{{ replace .Version "-" "." }}-{{ .Var.packageRelease }}.aarch64.rpm)
144177
145178
#### OSX Darwin
146179
@@ -198,7 +231,7 @@ release:
198231
# - glob: ./glob/foo/to/bar/file/foobar/override_from_previous
199232

200233
winget:
201-
-
234+
-
202235
# IDs of the archives to use.
203236
# Empty means all IDs.
204237
ids: [ default ]

scripts/package-repo-import.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
: ${GCLOUD_LOCATION:=us-central1}
6+
: ${GCLOUD_RPM_REPO:=rpms}
7+
: ${GCLOUD_DEB_REPO:=debs}
8+
9+
PACKAGE="${1}"
10+
VERSION="${2}"
11+
RELEASE="1"
12+
EPOCH="0"
13+
GORELEASER_PHASE=${GORELEASER_PHASE:-release}
14+
15+
echo "Package: ${PACKAGE}"
16+
echo "Version: ${VERSION}"
17+
18+
check_package() {
19+
local EXITCODE=0
20+
local REPO="${1}"
21+
local VER="${2}"
22+
if [ ! -f /tmp/version-deleted.stamp ]; then
23+
gcloud artifacts versions list \
24+
--repository "${REPO}" \
25+
--location "${GCLOUD_LOCATION}" \
26+
--package "${PACKAGE}" \
27+
--filter "VERSION:${VER}" \
28+
--format json 2> /dev/null \
29+
| jq -re '.[].name?' >/dev/null 2>&1 \
30+
|| EXITCODE=$?
31+
if [[ "${EXITCODE}" -eq 0 ]]; then
32+
echo "Package version already exists. Removing it..."
33+
gcloud artifacts versions delete \
34+
--quiet "${VER}" \
35+
--package "${PACKAGE}" \
36+
--repository "${REPO}" \
37+
--location "${GCLOUD_LOCATION}"
38+
touch /tmp/version-deleted.stamp
39+
fi
40+
fi
41+
}
42+
43+
if [[ ${IS_PRERELEASE} == "true" ]]; then
44+
echo "Skipping artifact import; IS_PRERELEASE is 'true'"
45+
exit 0;
46+
fi
47+
48+
check_package "${GCLOUD_RPM_REPO}" "${EPOCH}:${VERSION}-${RELEASE}"
49+
gcloud artifacts yum import "${GCLOUD_RPM_REPO}" \
50+
--location "${GCLOUD_LOCATION}" \
51+
--gcs-source "gs://artifacts-outgoing/${PACKAGE}/rpm/${VERSION}/*"
52+
53+
check_package ${GCLOUD_DEB_REPO} "${VERSION}-${RELEASE}"}
54+
gcloud artifacts apt import "${GCLOUD_DEB_REPO}" \
55+
--location "${GCLOUD_LOCATION}" \
56+
--gcs-source "gs://artifacts-outgoing/${PACKAGE}/deb/${VERSION}/*"

scripts/package-upload.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -x
5+
6+
FILE="${1}"
7+
PACKAGE="${2}"
8+
VERSION="${3}"
9+
10+
echo "Package File: ${FILE}"
11+
echo "Package: ${PACKAGE}"
12+
echo "Version: ${VERSION}"
13+
echo "Release: ${RELEASE}"
14+
echo "Location: ${GCLOUD_LOCATION}"
15+
16+
if [ "${FILE: -4}" == ".deb" ]; then
17+
if [[ "${FILE}" =~ "armhf6" ]]; then
18+
echo "Skipping ${FILE} due to GCP Artifact Registry armhf conflict!"
19+
else
20+
gcloud storage cp ${FILE} gs://artifacts-outgoing/${PACKAGE}/deb/${VERSION}/
21+
fi
22+
else
23+
gcloud storage cp ${FILE} gs://artifacts-outgoing/${PACKAGE}/rpm/${VERSION}/
24+
fi

0 commit comments

Comments
 (0)