Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for linux distribution packaging #2478

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,61 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package-deb:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get tag
id: get_tag
run: echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${TAG##v}
env:
TAG: ${{ steps.get_tag.outputs.TAG }}
- name: create gpg key
run: echo "${GPG_KEY}" > /root/gpg
env:
GPG_KEY: ${{ secrets.GPG_KEY }}
- name: import gpg key
run: gpg --pinentry-mode=loopback --passphrase "$GPG_PASSPHRASE" --import /root/gpg
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Install make
run: apt install make -y
- name: Build and package deb
run: make deb-source
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
package-rpm:
runs-on: ubuntu-latest
container: fedora:latest
needs: [goreleaser]
steps:
- name: Get tag
id: get_tag
run: echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${TAG##v}
env:
TAG: ${{ steps.get_tag.outputs.TAG }}
- name: Install make
run: dnf install make -y
- name: Setup rpm-build
run: make rpm-setup
- name: Build srpm
run: make srpm-build
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}
- name: Publish rpm
run: |
mkdir -p ~/.config
echo "${SCW_COPR_CONFIG}" > ~/.config/copr
copr-cli build @scaleway/staging ~/rpmbuild/SRPMS/scw-*.rpm
env:
SCW_COPR_CONFIG: ${{ secrets.SCW_COPR_CONFIG }}
61 changes: 61 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
SHELL=bash

rpm-setup:
sudo dnf groupinstall "RPM Development Tools" -y
sudo dnf install copr-cli -y
rpmdev-setuptree
sudo dnf install jq -y

template-rpm-spec: require-version
sed s/\%\{version_\}/${VERSION}/g specs/rpm/scaleway-cli.tmpl.spec > specs/rpm/scaleway-cli.spec
RELEASE_JSON="$$(curl https://api.github.com/repos/scaleway/scaleway-cli/releases/tags/v${VERSION})"; \
DATE=$$(date -d "$$(echo $${RELEASE_JSON} | jq ."created_at" -r)" "+%a %b %d %Y") ; \
CHANGELOG="$$(echo $${RELEASE_JSON} | jq ."body" -r | grep '^*' | sed s/^\*/-/g)"; \
echo "* $${DATE} Scaleway Devtools <[email protected]> - ${VERSION}" >> specs/rpm/scaleway-cli.spec; \
echo "$${CHANGELOG}" >> specs/rpm/scaleway-cli.spec

srpm-build: require-version template-rpm-spec
sudo dnf builddep specs/rpm/scaleway-cli.spec -y
spectool -g -R specs/rpm/scaleway-cli.spec --define "version_ ${VERSION}"
rpmbuild -ba specs/rpm/scaleway-cli.spec --define "version_ ${VERSION}"

rpm-build: srpm-build
cd ~/rpmbuild/
rpmbuild -bs

template-deb-setup:
apt install curl jq -y

template-deb: template-deb-setup require-version
RELEASE_JSON="$$(curl https://api.github.com/repos/scaleway/scaleway-cli/releases/tags/v${VERSION})"; \
CHANGELOG="$$(echo $${RELEASE_JSON} | jq ."body" -r | grep '^*' | sed s/^\*/\ \ \*/g)"; \
DATE=$$(date -d "$$(echo $${RELEASE_JSON} | jq ."created_at" -r)" -R) ; \
echo -e "scw (${VERSION}) focal; urgency=medium\n" > specs/deb/changelog; \
echo "$${CHANGELOG}" >> specs/deb/changelog; \
echo -e "\n -- Scaleway Devtools <[email protected]> $${DATE}" >> specs/deb/changelog

deb-setup:
apt install devscripts equivs -y
ln -fs specs/deb debian
mk-build-deps --install debian/control -t "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
go mod vendor

deb-source-build: require-version template-deb deb-setup
debuild -S -us -uc

deb-source-sign: require-version
echo '$(value GPG_PASSPHRASE)' > /tmp/key
debsign -k524A68BAB1A91B2F74DCEC3B31F9FBCA5BD8707C --re-sign -p"gpg --pinentry-mode=loopback --passphrase-file /tmp/key" ../scw_${VERSION}.dsc ../scw_${VERSION}_source.changes
rm /tmp/key

deb-source: deb-source-build deb-source-sign

deb-build:
debuild -b -us -uc

require-version:
ifndef VERSION
$(error VERSION is undefined)
endif

.PHONY: rpm-setup rpm-build srpm-build
2 changes: 1 addition & 1 deletion cmd/scw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (

// These are initialized by the build script

BuildDate = "unknown" // date -u '+%Y-%m-%d_%I:%M:%S%p'
BuildDate = "unknown" // RFC3339: date -u '+%Y-%m-%dT%H:%M:%SZ'
GitBranch = "unknown" // git symbolic-ref -q --short HEAD || echo HEAD"
GitCommit = "unknown" // git rev-parse --short HEAD

Expand Down
1 change: 1 addition & 0 deletions specs/deb/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## File should be updated by
13 changes: 13 additions & 0 deletions specs/deb/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Source: scw
Homepage: https://www.scaleway.com/
Maintainer: Scaleway Devtools <[email protected]>
Rules-Requires-Root: no
Build-Depends: debhelper-compat (= 13),
dh-golang,
golang-any,

Package: scw
Architecture: all
Description: Scaleway CLI
XS-Go-Import-Path: github.com/scaleway/scaleway-cli/v2/cmd/scw
Version: ${VERSION}
19 changes: 19 additions & 0 deletions specs/deb/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/make -f

export DH_GOPKG := github.com/scaleway/scaleway-cli/v2
export DH_GOLANG_BUILDPKG := ${DH_GOPKG}/cmd/scw

VERSION := $(shell dpkg-parsechangelog -SVersion)
SOURCE_DATE_EPOCH := $(shell git log -1 --pretty=%ct)
DATE := $(shell date --date="@${SOURCE_DATE_EPOCH}" -u '+%Y-%m-%dT%H:%M:%SZ')
GIT_BRANCH := $(shell git symbolic-ref -q --short HEAD || echo HEAD)
GIT_COMMIT := $(shell git rev-parse --short HEAD)

%:
dh $@ --builddirectory=_build

override_dh_auto_install:
dh_auto_install -- --no-source

override_dh_auto_build:
dh_auto_build -- -ldflags "-w -extldflags -static -X main.Version=${VERSION} -X main.BuildDate=${DATE} -X main.GitBranch=${GIT_BRANCH} -X main.GitCommit=${GIT_COMMIT}"
1 change: 1 addition & 0 deletions specs/rpm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scaleway-cli.spec
45 changes: 45 additions & 0 deletions specs/rpm/scaleway-cli.tmpl.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Name: scw
Version: %{version_}
Release: 1%{?dist}
Summary: Scaleway CLI

License: Apache License 2.0
URL: https://github.com/scaleway/scaleway-cli
Source0: https://github.com/scaleway/scaleway-cli/archive/refs/tags/v%{version}.tar.gz

%if 0%{?suse_version}
BuildRequires: go git
%else
BuildRequires: golang git
%endif

Provides: %{name} = %{version}

%description
Scaleway CLI

%global debug_package %{nil}

%prep
%autosetup -n scaleway-cli-%{version}

%define build_epoch %(git log -1 --pretty="%%ct")
%define build_date %(date --date="@%{build_epoch}" -u +"%%Y-%%m-%%dT%%H:%%M:%%SZ")
%define git_branch %(git symbolic-ref -q --short HEAD || echo HEAD)
%define git_commit %(git rev-parse --short HEAD)

%build
export CGO_ENABLED=0
LDFLAGS="-w -extldflags -static -X main.Version=%{version} -X main.BuildDate=%{build_date} -X main.GitBranch=%{git_branch} -X main.GitCommit=%{git_commit}"
GOPROXY=direct GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o %{name} cmd/scw/main.go


%install
install -Dpm 0755 %{name} %{buildroot}%{_bindir}/%{name}


%files
%{_bindir}/%{name}


%changelog