From 7e731654094c47fe3c0c4c910a52498c6bd84ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Roth?= Date: Sat, 21 Sep 2024 21:14:34 +0200 Subject: [PATCH] ci: use tag/branch for release/ci building --- .github/workflows/ci.yml | 38 +++++--------------------------------- Makefile | 14 +++++++++----- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63f5eb60..3e587549 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,13 +154,6 @@ jobs: with: go-version: ${{ steps.goversion.outputs.GOVER }} - - name: Check if CI or Release - run: | - releasetype=$(make releasetype) - echo "Release Type: $releasetype" - echo "RELEASETYPE=$releasetype" >> $GITHUB_OUTPUT - id: releasetype - - name: "Build Debian packages" env: GOBIN: /usr/local/bin @@ -168,7 +161,7 @@ jobs: make dpkg DEBARCH=${{ matrix.arch }} - name: "Publish CI release to aptly" - if: steps.releasetype.outputs.RELEASETYPE == 'ci' && github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' env: APTLY_USER: ${{ secrets.APTLY_USER }} APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }} @@ -176,7 +169,7 @@ jobs: ./upload-artifacts.sh ci ${{ matrix.suite }} - name: "Publish release to aptly" - if: steps.releasetype.outputs.RELEASETYPE == 'release' && github.ref == 'refs/heads/master' + if: startsWith(github.event.ref, 'refs/tags') env: APTLY_USER: ${{ secrets.APTLY_USER }} APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }} @@ -203,13 +196,6 @@ jobs: # fetch the whole repo for `git describe` to work fetch-depth: 0 - - name: "Check if CI or Release" - run: | - releasetype=$(make releasetype) - echo "Release Type: $releasetype" - echo "RELEASETYPE=$releasetype" >> $GITHUB_OUTPUT - id: releasetype - - name: "Read go version from go.mod" run: | echo "GOVER=$(sed -n 's/^go \(.*\)/\1/p' go.mod)" >> $GITHUB_OUTPUT @@ -234,39 +220,25 @@ jobs: make binaries GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} - uses: actions/upload-artifact@v4 - if: steps.releasetype.outputs.RELEASETYPE == 'release' && github.ref == 'refs/heads/master' + if: startsWith(github.event.ref, 'refs/tags') with: name: aptly_${{ steps.releaseversion.outputs.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }} path: build/aptly_${{ steps.releaseversion.outputs.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip - retention-days: 90 + compression-level: 0 # no compression gh-release: name: "Github Release" runs-on: ubuntu-latest continue-on-error: false needs: ci-binary-build + if: startsWith(github.event.ref, 'refs/tags') steps: - - name: "Checkout repository" - uses: actions/checkout@v3 - with: - # fetch the whole repo for `git describe` to work - fetch-depth: 0 - - - name: "Check if CI or Release" - run: | - releasetype=$(make releasetype) - echo "Release Type: $releasetype" - echo "RELEASETYPE=$releasetype" >> $GITHUB_OUTPUT - id: releasetype - - name: "Download Artifacts" - if: steps.releasetype.outputs.RELEASETYPE == 'release' && github.ref == 'refs/heads/master' uses: actions/download-artifact@v4 with: path: out/ - name: "Release" - if: steps.releasetype.outputs.RELEASETYPE == 'release' && github.ref == 'refs/heads/master' uses: softprops/action-gh-release@v2 with: files: "out/**/aptly_*.zip" diff --git a/Makefile b/Makefile index a3c705bc..9688ebff 100644 --- a/Makefile +++ b/Makefile @@ -101,11 +101,15 @@ version: ## Print aptly version fi releasetype: # Print release type (ci/release) - @if [ -z "`git tag --points-at HEAD`" ]; then \ - echo ci ; \ - else \ - echo release ; \ - fi + @reltype=ci ; \ + gitbranch=`git rev-parse --abbrev-ref HEAD` ; \ + if [ "$$gitbranch" = "HEAD" ]; then \ + gittag=`git describe --tags --exact-match` ;\ + if echo "$$gittag" | grep -q '^v[0-9]'; then \ + reltype=release ; \ + fi ; \ + fi ; \ + echo $$reltype build: ## Build aptly go mod tidy