From 302880b72e207b536d51759a7304aeef6c9276aa Mon Sep 17 00:00:00 2001 From: Sig Date: Sat, 24 Feb 2024 10:49:58 -0800 Subject: [PATCH] Better ci (#4) * add version vars introduced by goreleaser * small change * cleanup release workflow --- .github/workflows/release.yml | 124 ++++++---------------------------- .goreleaser.yaml | 38 +++++++++++ cmd/runitcmd/main.go | 6 ++ 3 files changed, 64 insertions(+), 104 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c1fd689..dc0f945 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,115 +1,31 @@ -name: Build debian package (.deb) +name: goreleaser on: push: - #branches: [ master ] + branches: [ "better-ci" ] tags: [ 'v*' ] -jobs: - - build: - runs-on: ubuntu-latest - strategy: - matrix: - codename: [focal] - steps: - - uses: actions/checkout@v2 - - - name: Unshallow - run: git fetch --prune --unshallow - - - name: Build debian package - uses: sigmonsays/dpkg-buildpackage-go@master - - - name: list files - run: ls -l *.deb - - - name: Upload result - uses: actions/upload-artifact@v2 - with: - name: ${{ matrix.codename }} - path: | - *.deb - - test: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Download artifact - uses: actions/download-artifact@v2 - with: - name: ${{ matrix.codename }} - path: artifact +permissions: + contents: write - release: - needs: test +jobs: + goreleaser: runs-on: ubuntu-latest steps: - - name: Create release - id: create_release - uses: actions/create-release@v1.1.4 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Checkout + uses: actions/checkout@v3 with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - commitish: ${{ github.sha }} - draft: false - prerelease: false - outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} - - upload: - needs: release - runs-on: ubuntu-latest - strategy: - matrix: - codename: [focal] - steps: - - name: Download artifact - uses: actions/download-artifact@v2 + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v4 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 with: - name: ${{ matrix.codename }} - path: ${{ matrix.codename }} - - name: list files - shell: bash - run: find - - - name: Get Name of Artifact - run: | - ARTIFACT_PATHNAME=$(ls ${{ matrix.codename }}/*.deb | head -n 1) - ARTIFACT_NAME=$(basename $ARTIFACT_PATHNAME) - echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV - echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV - - - name: Upload release asset - uses: actions/upload-release-asset@v1.0.2 + distribution: goreleaser + version: latest + args: release --clean env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.release.outputs.upload_url }} - # asset_path: ${{ matrix.codename }} - # asset_name: ${{ matrix.codename }} - asset_path: ${{ env.ARTIFACT_PATHNAME }} - asset_name: ${{ env.ARTIFACT_NAME }} - asset_content_type: application/deb - - release-binaries: - name: release linux/amd64 - needs: release - runs-on: ubuntu-latest - strategy: - matrix: - goos: [linux, windows, darwin] - goarch: ["386", amd64] - steps: - - uses: actions/checkout@v2 - - uses: wangyoucao577/go-release-action@v1.14 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - project_path: ./cmd/runitcmd - binary_name: runitcmd - goos: ${{ matrix.goos }} - goarch: ${{ matrix.goarch }} - #goversion: "https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz" + GITHUB_TOKEN: ${{ secrets.GH_PAT }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..a0078cc --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,38 @@ +# before: +# hooks: +# - go mod tidy +# - go generate ./... +builds: + - main: ./cmd/runitcmd + env: + - CGO_ENABLED=0 + goos: + - linux + # - windows + # - darwin + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +# The lines beneath this are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/cmd/runitcmd/main.go b/cmd/runitcmd/main.go index 1e61dca..e6f5ec2 100644 --- a/cmd/runitcmd/main.go +++ b/cmd/runitcmd/main.go @@ -19,6 +19,12 @@ type Application struct { Runit *runit.Runit } +var ( + version = "dev" + commit = "none" + date = "unknown" +) + func main() { c := cli.NewApp() c.Name = "runitcmd"