|
| 1 | +name: build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'master' |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + |
| 10 | +env: |
| 11 | + GO111MODULE: off |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - |
| 18 | + name: Set up Go |
| 19 | + uses: actions/setup-go@v2 |
| 20 | + with: |
| 21 | + go-version: 1.19 |
| 22 | + |
| 23 | + - |
| 24 | + name: Install Cloudsmith CLI |
| 25 | + run: pip install --upgrade cloudsmith-cli |
| 26 | + # Cloudsmith CLI tooling for pushing releases |
| 27 | + # See https://help.cloudsmith.io/docs/cli |
| 28 | + |
| 29 | + - |
| 30 | + name: Checkout |
| 31 | + uses: actions/checkout@v2 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - |
| 36 | + name: Tests |
| 37 | + run: | |
| 38 | + export GOPATH=/home/runner/go |
| 39 | + mkdir -vp $GOPATH/src/github.com/$GITHUB_REPOSITORY |
| 40 | + rmdir -v $GOPATH/src/github.com/$GITHUB_REPOSITORY |
| 41 | + mv -v $GITHUB_WORKSPACE $GOPATH/src/github.com/$GITHUB_REPOSITORY |
| 42 | + ln -vs $GOPATH/src/github.com/$GITHUB_REPOSITORY $GITHUB_WORKSPACE |
| 43 | + # go mod tidy |
| 44 | + go get -v ./... |
| 45 | + go build -v |
| 46 | + go test -v ./... |
| 47 | +
|
| 48 | + - |
| 49 | + name: Run GoReleaser |
| 50 | + uses: goreleaser/goreleaser-action@v2 |
| 51 | + if: success() && startsWith(github.ref, 'refs/tags/') |
| 52 | + with: |
| 53 | + version: latest |
| 54 | + args: release --rm-dist |
| 55 | + env: |
| 56 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + # Publish to cloudsmith repo |
| 59 | + - |
| 60 | + name: Publish package to cloudsmith |
| 61 | + if: success() && startsWith(github.ref, 'refs/tags/') |
| 62 | + env: |
| 63 | + CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} |
| 64 | + run: | |
| 65 | + for filepath in dist/*; do |
| 66 | + echo "== Analyzing '$filepath' for publishing" |
| 67 | + filename=$(basename -- "$filepath") |
| 68 | + extension="${filename##*.}" |
| 69 | + filename="${filename%.*}" |
| 70 | + case "$extension" in |
| 71 | + 'apk') |
| 72 | + echo "Pushing '$filepath' to cloudsmith repo" |
| 73 | + cloudsmith push alpine suntong/repo/alpine/any-version $filepath |
| 74 | + ;; |
| 75 | + 'deb' | 'rpm') |
| 76 | + echo "Pushing '$filepath' to cloudsmith repo" |
| 77 | + cloudsmith push $extension suntong/repo/any-distro/any-version $filepath |
| 78 | + ;; |
| 79 | + *) |
| 80 | + echo "File .$extension skipped publishing" |
| 81 | + echo |
| 82 | + ;; |
| 83 | + esac |
| 84 | + done |
0 commit comments