diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 63c0dd4313..38fd80b5ba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000000..24ff9876fc --- /dev/null +++ b/GNUmakefile @@ -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 - ${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 $${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 diff --git a/cmd/scw/main.go b/cmd/scw/main.go index 1f3f73165f..06ac754ed8 100644 --- a/cmd/scw/main.go +++ b/cmd/scw/main.go @@ -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 diff --git a/specs/deb/changelog b/specs/deb/changelog new file mode 100644 index 0000000000..9fad0afc72 --- /dev/null +++ b/specs/deb/changelog @@ -0,0 +1 @@ +## File should be updated by \ No newline at end of file diff --git a/specs/deb/control b/specs/deb/control new file mode 100644 index 0000000000..e9cd75eb0a --- /dev/null +++ b/specs/deb/control @@ -0,0 +1,13 @@ +Source: scw +Homepage: https://www.scaleway.com/ +Maintainer: Scaleway Devtools +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} \ No newline at end of file diff --git a/specs/deb/rules b/specs/deb/rules new file mode 100755 index 0000000000..c38ccf43b6 --- /dev/null +++ b/specs/deb/rules @@ -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}" diff --git a/specs/rpm/.gitignore b/specs/rpm/.gitignore new file mode 100644 index 0000000000..e2c466f3da --- /dev/null +++ b/specs/rpm/.gitignore @@ -0,0 +1 @@ +scaleway-cli.spec \ No newline at end of file diff --git a/specs/rpm/scaleway-cli.tmpl.spec b/specs/rpm/scaleway-cli.tmpl.spec new file mode 100644 index 0000000000..3f9a585a7f --- /dev/null +++ b/specs/rpm/scaleway-cli.tmpl.spec @@ -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