Skip to content

Commit

Permalink
improve CI workflow
Browse files Browse the repository at this point in the history
- use debian version consistently
- if the commit is not on a git tag, append ci version
- avoid double zipping
- cleanup binary builds
- replace `make release` with `make binaries`
- add missing files to archives
- use matrix build for deb packages
- allow building release version
- keep directory inside zip archives
- accept releases only on master
  only tags on master will trigger a release
- cleanup namings
- keep path in zip
- add retention period for pipeline artifacts
  • Loading branch information
neolynx committed Sep 19, 2024
1 parent 9be7eb5 commit 9d0e1c6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
51 changes: 33 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ jobs:
files: coverage.txt

ci-debian-build:
name: "CI Build"
name: "Build"
needs: test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
name: ["Debian 13/testing", "Debian 12/bookworm", "Debian 11/bullseye", "Debian 10/buster", "Ubuntu 24.04", "Ubuntu 22.04", "Ubuntu 20.04"]
arch: ["amd64", "i386" , "arm64" , "armhf"]
include:
- name: "Debian 13/testing"
suite: trixie
Expand Down Expand Up @@ -151,16 +152,29 @@ jobs:
with:
go-version: ${{ steps.goversion.outputs.GOVER }}

- name: Check is CI or Release
run: |
if [ -z "`git tag --points-at HEAD`" ]; then
releasetype=ci
else
releasetype=release
fi
echo RELEASETYPE=$releasetype >> $GITHUB_OUTPUT
id: releasetype

- name: "Build Debian packages"
env:
GOBIN: /usr/local/bin
run: |
GOPATH=$PWD/.go go generate -v
DEBEMAIL="CI <runner@github>" dch -v `make version` "CI build"
dpkg-buildpackage -us -uc -b -d --host-arch=amd64
dpkg-buildpackage -us -uc -b -d --host-arch=i386
dpkg-buildpackage -us -uc -b -d --host-arch=arm64
dpkg-buildpackage -us -uc -b -d --host-arch=armhf
if [ "${{ steps.releasetype.outputs.RELEASETYPE }}" = "ci" ]; then
DEBEMAIL="CI <runner@github>" 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
Expand All @@ -173,15 +187,15 @@ jobs:
./upload-artifacts.sh ci ${{ matrix.suite }}
- name: "Publish release to aptly"
if: startsWith(github.event.ref, 'refs/tags')
if: steps.releasetype.outputs.RELEASETYPE == 'release' && github.ref == 'refs/heads/master'
env:
APTLY_USER: ${{ secrets.APTLY_USER }}
APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }}
run: |
./upload-artifacts.sh release ${{ matrix.suite }}
ci-release-build:
name: "CI Build (Binary)"
ci-binary-build:
name: "Build"
needs: test
runs-on: ubuntu-latest
strategy:
Expand All @@ -207,32 +221,33 @@ jobs:

- name: "Get aptly version"
run: |
# Because dpkg-parsechangelog is not installed, will return the latest git tag
echo "VERSION=$(make version RELEASE=yes)" >> $GITHUB_OUTPUT
echo "VERSION=$(make version)" >> $GITHUB_OUTPUT
id: releaseversion

- name: "Setup Go"
uses: actions/setup-go@v3
with:
go-version: ${{ steps.goversion.outputs.GOVER }}

- name: "Build packages for ${{ matrix.goos }} ${{ matrix.goarch }}"
- name: "Build aptly ${{ matrix.goos }}/${{ matrix.goarch }}"
env:
GOBIN: /usr/local/bin
run: |
echo ${{ steps.releaseversion.outputs.VERSION }} > VERSION
make release GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }}
make binaries GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }}
cd build; unzip aptly_${{ steps.releaseversion.outputs.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip
rm -f aptly_${{ steps.releaseversion.outputs.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip
- uses: actions/upload-artifact@v4
with:
name: aptly_${{ steps.releaseversion.outputs.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip
path: build/aptly_${{ steps.releaseversion.outputs.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip
name: aptly_${{ steps.releaseversion.outputs.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}
path: build/*
retention-days: 90

gh-release:
name: "Github Release: ${{ github.ref_name }}"
name: "Github Release"
runs-on: ubuntu-latest
continue-on-error: false
needs: ci-release-build
needs: ci-binary-build
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download Artifacts
Expand Down
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,29 @@ man: ## Create man pages
make -C man

version: ## Print aptly version
@ts=`TZ=UTC git show -s --format='%cd.%h' --date=format-local:'%Y%m%d%H%M%S'`; \
@ci="" ; \
if [ -z "`git tag --points-at HEAD`" ]; then \
ci=`TZ=UTC git show -s --format='+%cd.%h' --date=format-local:'%Y%m%d%H%M%S'`; \
fi ; \
if which dpkg-parsechangelog > /dev/null 2>&1; then \
if [ -z "$$ts" ]; then \
dpkg-parsechangelog -S Version; \
else \
echo `dpkg-parsechangelog -S Version`+$$ts; \
fi \
echo `dpkg-parsechangelog -S Version`$$ci; \
else \
git describe --tags --always | sed 's@^v@@' | sed 's@-@+@g'; \
echo `grep ^aptly -m1 debian/changelog | sed 's/.*(\([^)]\+\)).*/\1/'`$$ci ; \
fi

build: ## Build aptly
go mod tidy
go generate
go build -o build/aptly

release: version ## build release archive in build/ for GOOS and GOARCH
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
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o build/tmp/aptly -ldflags='-extldflags=-static'
@cp man/aptly.1 build/tmp/man/
@cp completion.d/aptly build/tmp/completion/bash_completion.d/
@cp completion.d/_aptly build/tmp/completion/zsh/vendor-completions/
@cp README.rst LICENSE AUTHORS build/tmp/
@gzip -f build/tmp/man/aptly.1
@path="aptly_$(VERSION)_$(GOOS)_$(GOARCH)"; \
rm -rf "build/$$path"; \
Expand Down Expand Up @@ -143,8 +144,8 @@ docker-system-tests: ## Run system tests in docker container (add TEST=t04_mirr
docker-lint: ## Run golangci-lint in docker container
@docker run -it --rm -v ${PWD}:/app -e GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) aptly-dev /app/system/run-golangci-lint

docker-release:
@docker run -it --rm -v ${PWD}:/app aptly-dev /app/system/run-release
docker-binaries: ## Build binary releases (FreeBSD, MacOS, Linux tar) in docker container
@docker run -it --rm -v ${PWD}:/app aptly-dev /app/system/build-binaries

flake8: ## run flake8 on system tests
flake8 system
Expand All @@ -153,4 +154,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 release docker-build-aptly-dev docker-system-tests docker-unit-tests docker-lint docker-build 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
2 changes: 1 addition & 1 deletion system/run-release → system/build-binaries
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ rm -rf /app/build/tmp
usermod -u `stat -c %u /app` aptly >/dev/null
chown -R `stat -c %u /app` /var/lib/aptly

su - aptly -c "cd /app; export GOPATH=/app/.go; make release"
su - aptly -c "cd /app; export GOPATH=/app/.go; make binaries"

0 comments on commit 9d0e1c6

Please sign in to comment.