aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/go-release-build.yml
blob: 11e68d5ed205aa3c0b1e97c7c8b4e1e183bd6dda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: build

on:
  push:
    branches:
      - 'master'
    tags:
      - 'v*'

env:
  GO111MODULE: off

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      -
        name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.17

      -
        name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      -
        name: Tests
        run: |
          export GOPATH=/home/runner/go
          mkdir -vp $GOPATH/src/github.com/$GITHUB_REPOSITORY
          rmdir -v $GOPATH/src/github.com/$GITHUB_REPOSITORY
          mv -v $GITHUB_WORKSPACE $GOPATH/src/github.com/$GITHUB_REPOSITORY
          ln -vs $GOPATH/src/github.com/$GITHUB_REPOSITORY $GITHUB_WORKSPACE
          # go mod tidy
          go get -v ./...
          go build -v
          go test -v ./...

      -
        name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2
        if: success() && startsWith(github.ref, 'refs/tags/')
        with:
          version: latest
          args: release --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      -
        name: Install Cloudsmith CLI
        if: success() && startsWith(github.ref, 'refs/tags/')
        run: pip install --upgrade cloudsmith-cli
        # Cloudsmith CLI tooling for pushing releases
        # See https://help.cloudsmith.io/docs/cli

      # Publish to cloudsmith repo
      -
        name: Publish package to cloudsmith
        if: success() && startsWith(github.ref, 'refs/tags/')
        env:
          CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
        run: |
          for filepath in dist/*; do
            echo "== Analyzing '$filepath' for publishing"
            filename=$(basename -- "$filepath")
            extension="${filename##*.}"
            filename="${filename%.*}"
            case "$extension" in
            'apk')
              echo "Pushing '$filepath' to cloudsmith repo"
              cloudsmith push alpine suntong/repo/alpine/any-version $filepath
              ;;
            'deb' | 'rpm')
              echo "Pushing '$filepath' to cloudsmith repo"
              cloudsmith push $extension suntong/repo/any-distro/any-version $filepath
              ;;
            *)
              echo "File .$extension skipped publishing"
              echo
              ;;
            esac
          done