|
1 |
| -name: release |
| 1 | +name: Release |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | push:
|
5 | 5 | tags:
|
6 |
| - - '*' |
| 6 | + - 'v*' |
7 | 7 | workflow_dispatch:
|
8 | 8 |
|
9 |
| -jobs: |
| 9 | +env: |
| 10 | + CLOUDCAT: "cloudcat" |
| 11 | + BINARY_SUFFIX: "" |
| 12 | + CCATCTL: "ccatctl" |
| 13 | + COMMIT_ID: "${{ github.sha }}" |
10 | 14 |
|
11 |
| - release: |
| 15 | +jobs: |
| 16 | + build: |
12 | 17 | runs-on: ubuntu-latest
|
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + # build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 |
| 21 | + goos: [linux, windows, darwin] |
| 22 | + goarch: ["386", amd64, arm, arm64] |
| 23 | + exclude: |
| 24 | + - goos: darwin |
| 25 | + goarch: arm |
| 26 | + - goos: darwin |
| 27 | + goarch: "386" |
| 28 | + fail-fast: true |
13 | 29 | steps:
|
14 |
| - - uses: actions/checkout@v2 |
15 |
| - - uses: actions/cache@v2 |
16 |
| - with: |
17 |
| - path: | |
18 |
| - ~/.cache/go-build |
19 |
| - ~/go/pkg/mod |
20 |
| - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
21 |
| - restore-keys: | |
22 |
| - ${{ runner.os }}-go- |
23 |
| - - name: Set up Go |
24 |
| - uses: actions/setup-go@v2 |
25 |
| - with: |
26 |
| - go-version: 1.16 |
| 30 | + - uses: actions/checkout@v3 |
| 31 | + |
| 32 | + - name: Set up Go |
| 33 | + uses: actions/setup-go@v4 |
| 34 | + with: |
| 35 | + go-version: '1.21' |
27 | 36 |
|
28 |
| - - name: Test |
29 |
| - run: go test -v ./... |
| 37 | + - name: Lint |
| 38 | + uses: golangci/golangci-lint-action@v3 |
| 39 | + with: |
| 40 | + version: latest |
30 | 41 |
|
31 |
| - - name: Build |
32 |
| - run: make target |
| 42 | + - name: Tests |
| 43 | + run: | |
| 44 | + go test $(go list ./...) |
33 | 45 |
|
34 |
| - - name: Set up QEMU |
35 |
| - uses: docker/setup-qemu-action@v1 |
36 |
| - - name: Set up Docker Buildx |
37 |
| - uses: docker/setup-buildx-action@v1 |
38 |
| - - name: Login to DockerHub |
39 |
| - uses: docker/login-action@v1 |
40 |
| - with: |
41 |
| - username: ${{ secrets.DOCKERHUB_USERNAME }} |
42 |
| - password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 46 | + - name: Build binary file |
| 47 | + env: |
| 48 | + GOOS: ${{ matrix.goos }} |
| 49 | + GOARCH: ${{ matrix.goarch }} |
| 50 | + run: | |
| 51 | + if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi |
| 52 | + export CGO_ENABLED=0 |
| 53 | + export LD_FLAGS="-w -s -X github.com/scriptscat/cloudcat/configs.Version=${COMMIT_ID::7}" |
43 | 54 |
|
44 |
| - - name: Get version |
45 |
| - id: get_version |
46 |
| - run: echo ::set-output name=VERSION::${GITHUB_REF:10} |
| 55 | + go build -o "bin/${CLOUDCAT}${BINARY_SUFFIX}" -trimpath -ldflags "$LD_FLAGS" ./cmd/cloudcat |
| 56 | + go build -o "bin/${CCATCTL}${BINARY_SUFFIX}" -trimpath -ldflags "$LD_FLAGS" ./cmd/ccatctl |
47 | 57 |
|
48 |
| - - name: Build and push |
49 |
| - id: docker_build |
50 |
| - uses: docker/build-push-action@v2 |
51 |
| - with: |
52 |
| - push: true |
53 |
| - tags: codfrm/cloudcat:${{ steps.get_version.outputs.VERSION }} |
| 58 | + cd bin |
| 59 | + if [ "${{ matrix.goos }}" = "windows" ]; then |
| 60 | + zip -j "${CLOUDCAT}_${GOOS}_${GOARCH}.zip" "${CCATCTL}.exe" "${CLOUDCAT}.exe" |
| 61 | + else |
| 62 | + tar czvf "${CLOUDCAT}_${GOOS}_${GOARCH}.tar.gz" "${CCATCTL}" "${CLOUDCAT}" |
| 63 | + fi |
54 | 64 |
|
55 |
| - - name: Create Release |
56 |
| - id: create_release |
57 |
| - uses: actions/create-release@latest |
58 |
| - env: |
59 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
60 |
| - with: |
61 |
| - tag_name: ${{ github.ref }} |
62 |
| - release_name: ${{ github.ref }} |
63 |
| - body: | |
64 |
| - 'no description' |
65 |
| - draft: false |
66 |
| - prerelease: false |
| 65 | + - name: Upload artifact |
| 66 | + uses: actions/upload-artifact@v3 |
| 67 | + if: ${{ matrix.goos != 'windows' }} |
| 68 | + with: |
| 69 | + name: ${{ matrix.goos }}_${{ matrix.goarch }} |
| 70 | + path: bin/*.tar.gz |
67 | 71 |
|
68 |
| - - name: Build Target |
69 |
| - run: | |
70 |
| - VERSION=${{ steps.get_version.outputs.VERSION }} GOOS=linux GOARCH=amd64 make target |
71 |
| - tar -zcvf cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64 |
| 72 | + - name: Upload windows artifact |
| 73 | + uses: actions/upload-artifact@v3 |
| 74 | + if: ${{ matrix.goos == 'windows' }} |
| 75 | + with: |
| 76 | + name: ${{ matrix.goos }}_${{ matrix.goarch }} |
| 77 | + path: bin/*.zip |
| 78 | + |
| 79 | + release: |
| 80 | + needs: build |
| 81 | + runs-on: ubuntu-latest |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@v3 |
| 84 | + # 拿到build产物 |
| 85 | + - uses: actions/download-artifact@v3 |
| 86 | + with: |
| 87 | + path: bin/ |
72 | 88 |
|
73 |
| - - name: Upload Release Asset zip |
74 |
| - uses: actions/upload-release-asset@v1 |
75 |
| - env: |
76 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
77 |
| - with: |
78 |
| - upload_url: ${{ steps.create_release.outputs.upload_url }} |
79 |
| - asset_path: cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz |
80 |
| - asset_name: cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz |
81 |
| - asset_content_type: application/tar+gz |
| 89 | + - uses: ncipollo/release-action@v1 |
| 90 | + with: |
| 91 | + artifacts: "bin/*/*.tar.gz,bin/*/*.zip" |
| 92 | + body: "no describe" |
| 93 | + # 判断是否为预发布(包含alpha、beta等关键字) |
| 94 | + prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }} |
0 commit comments