Skip to content

Commit

Permalink
ci: add deb and rpm packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Aug 4, 2022
1 parent c49c798 commit 3cff110
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,58 @@ 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: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Add packaging config to goreleaser config
run: cat .goreleaser.pkg.yml >> .goreleaser.yml
- name: create gpg key
run: echo "${GPG_KEY}" > /root/gpg
env:
GPG_KEY: ${{ secrets.GPG_KEY }}
- name: Build and package deb
run: ./goreleaser release --skip-validate --rm-dist --skip-publish
# - name: Build and package deb
# uses: goreleaser/goreleaser-action@v2
# with:
# version: latest
# args: release --skip-validate --rm-dist --skip-publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_KEY: '/root/gpg'
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 }}
16 changes: 16 additions & 0 deletions .goreleaser.pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
nfpms:
-
package_name: scw
vendor: Scaleway
homepage: https://www.scaleway.com/
description: Scaleway CLI is a tool to help you pilot your Scaleway infrastructure directly from your terminal.
maintainer: Scaleway Devtools <[email protected]>
license: Apache 2.0
formats:
- deb
deb:
signature:
key_file: '{{ .Env.GPG_KEY }}'
key_id: F5BF26CADF6F9614
type: origin

1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ blobs:
- glob: scw-cli-v2-version
ids:
- binaries

31 changes: 31 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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

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

.PHONY: rpm-setup rpm-build srpm-build
41 changes: 41 additions & 0 deletions specs/rpm/scaleway-cli.tmpl.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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}


%build
export CGO_ENABLED=0
LDFLAGS="-w -extldflags -static -X main.Version=%{version}"
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

0 comments on commit 3cff110

Please sign in to comment.