From 02d080955be487a6132d9698df93629fe743aa9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Roth?= Date: Sat, 21 Sep 2024 10:53:37 +0200 Subject: [PATCH] ci: move scripts to makefile --- .github/workflows/ci.yml | 35 +++++++++++------------------------ Makefile | 27 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4db5889..4b67d6c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,9 @@ jobs: - name: "Read go version from go.mod" run: | - echo "GOVER=$(sed -n 's/^go \(.*\)/\1/p' go.mod)" >> $GITHUB_OUTPUT + gover=$(sed -n 's/^go \(.*\)/\1/p' go.mod) + echo "Go Version: $gover" + echo "GOVER=$gover" >> $GITHUB_OUTPUT id: goversion - name: "Setup Go" @@ -51,10 +53,6 @@ jobs: with: go-version: ${{ steps.goversion.outputs.GOVER }} - - name: "Get aptly version" - run: | - make version - - name: "Setup Python" uses: actions/setup-python@v4 with: @@ -144,7 +142,9 @@ jobs: - name: "Read go version from go.mod" run: | - echo "GOVER=$(sed -n 's/^go \(.*\)/\1/p' go.mod)" >> $GITHUB_OUTPUT + gover=$(sed -n 's/^go \(.*\)/\1/p' go.mod) + echo "Go Version: $gover" + echo "GOVER=$gover" >> $GITHUB_OUTPUT id: goversion - name: "Setup Go" @@ -152,31 +152,18 @@ jobs: with: go-version: ${{ steps.goversion.outputs.GOVER }} - - name: Check is CI or Release + - name: Check if CI or Release run: | - if [ -z "`git tag --points-at HEAD`" ]; then - releasetype=ci - else - releasetype=release - fi - echo RELEASETYPE=$releasetype >> $GITHUB_OUTPUT + releasetype=$(make releasetype) + echo "Release Type: $releasetype" + echo "RELEASETYPE=$releasetype" >> $GITHUB_OUTPUT id: releasetype - name: "Build Debian packages" env: GOBIN: /usr/local/bin run: | - GOPATH=$PWD/.go go generate -v - if [ "${{ steps.releasetype.outputs.RELEASETYPE }}" = "ci" ]; then - DEBEMAIL="CI " dch -v `make version` "CI build" - fi - buildtype="any" - if [ "${{ matrix.arch }}" = "amd64" ]; then # build 'all' type package only on amd64 - buildtype="any,all" - fi - dpkg-buildpackage -us -uc --build=$buildtype -d --host-arch=${{ matrix.arch }} - mkdir -p build && mv ../*.deb build/ - cd build && ls -l *.deb + make dpkg DEBARCH=${{ matrix.arch }} - name: "Publish CI release to aptly" if: github.ref == 'refs/heads/master' diff --git a/Makefile b/Makefile index b3311f5f..a3c705bc 100644 --- a/Makefile +++ b/Makefile @@ -100,11 +100,36 @@ version: ## Print aptly version echo `grep ^aptly -m1 debian/changelog | sed 's/.*(\([^)]\+\)).*/\1/'`$$ci ; \ fi +releasetype: # Print release type (ci/release) + @if [ -z "`git tag --points-at HEAD`" ]; then \ + echo ci ; \ + else \ + echo release ; \ + fi + build: ## Build aptly go mod tidy go generate go build -o build/aptly +dpkg: ## Build debian packages + @test -n "$(DEBARCH)" || (echo "please define DEBARCH"; exit 1) + GOPATH=$$PWD/.go go generate -v + @if [ "`make -s releasetype`" = "ci" ]; then \ + echo CI Build, setting version... ; \ + cp debian/changelog debian/changelog.dpkg-bak ; \ + DEBEMAIL="CI " dch -v `make -s version` "CI build" ; \ + fi + buildtype="any" ; \ + if [ "$(DEBARCH)" = "amd64" ]; then \ + buildtype="any,all" ; \ + fi ; \ + echo Building: $$buildtype ; \ + dpkg-buildpackage -us -uc --build=$$buildtype -d --host-arch=$(DEBARCH) + @test -f debian/changelog.dpkg-bak && mv debian/changelog.dpkg-bak debian/changelog || true ; \ + mkdir -p build && mv ../*.deb build/ ; \ + cd build && ls -l *.deb + binaries: ## Build binary releases (FreeBSD, MacOS, Linux tar) @mkdir -p build/tmp/man build/tmp/completion/bash_completion.d build/tmp/completion/zsh/vendor-completions @make version > VERSION @@ -154,4 +179,4 @@ clean: ## remove local build and module cache test -d .go/ && chmod u+w -R .go/ && rm -rf .go/ || true rm -rf build/ docs/ obj-*-linux-gnu* -.PHONY: help man prepare version binaries docker-release docker-system-tests docker-unit-tests docker-lint docker-build docker-image build docker-aptly clean +.PHONY: help man prepare version binaries docker-release docker-system-tests docker-unit-tests docker-lint docker-build docker-image build docker-aptly clean releasetype dpkg