github.com/nxtrace/NTrace-core@v1.3.1-0.20240513132635-39169291e8c9/.github/workflows/build.yml (about) 1 name: Build & Release 2 3 on: 4 workflow_dispatch: 5 push: 6 branches: 7 - main 8 tags: 9 - "v*" 10 paths: 11 - "**/*.go" 12 - "go.mod" 13 - "go.sum" 14 - ".github/workflows/*.yml" 15 pull_request: 16 types: [opened, synchronize, reopened] 17 paths: 18 - "**/*.go" 19 - "go.mod" 20 - "go.sum" 21 - ".github/workflows/*.yml" 22 jobs: 23 build: 24 runs-on: ubuntu-latest 25 strategy: 26 matrix: 27 # Include amd64 on all platforms. 28 goos: [windows, freebsd, openbsd, linux, dragonfly, darwin] 29 goarch: [amd64, 386] 30 exclude: 31 # Exclude i386 on darwin and dragonfly. 32 - goarch: 386 33 goos: dragonfly 34 - goarch: 386 35 goos: darwin 36 include: 37 # BEIGIN MacOS ARM64 38 - goos: darwin 39 goarch: arm64 40 # END macOS ARM64 41 # BEGIN Linux ARM 5 6 7 42 - goos: linux 43 goarch: arm 44 goarm: 7 45 - goos: linux 46 goarch: arm 47 goarm: 6 48 - goos: linux 49 goarch: arm 50 goarm: 5 51 # END Linux ARM 5 6 7 52 # BEGIN Android ARM 8 53 - goos: android 54 goarch: arm64 55 # END Android ARM 8 56 # Windows ARM 57 - goos: windows 58 goarch: arm64 59 - goos: windows 60 goarch: arm 61 goarm: 7 62 # BEGIN Other architectures 63 # BEGIN riscv64 & ARM64 64 - goos: linux 65 goarch: arm64 66 - goos: linux 67 goarch: riscv64 68 # END riscv64 & ARM64 69 # BEGIN MIPS 70 - goos: linux 71 goarch: mips64 72 - goos: linux 73 goarch: mips64le 74 - goos: linux 75 goarch: mipsle 76 - goos: linux 77 goarch: mips 78 - goos: linux 79 goarch: mipsle 80 gomips: softfloat 81 - goos: linux 82 goarch: mips 83 gomips: softfloat 84 # END MIPS 85 # BEGIN PPC 86 - goos: linux 87 goarch: ppc64 88 - goos: linux 89 goarch: ppc64le 90 # END PPC 91 # BEGIN FreeBSD ARM 92 - goos: freebsd 93 goarch: arm64 94 - goos: freebsd 95 goarch: arm 96 goarm: 7 97 # END FreeBSD ARM 98 # BEGIN S390X 99 - goos: linux 100 goarch: s390x 101 # END S390X 102 # END Other architectures 103 # BEGIN OPENBSD ARM 104 - goos: openbsd 105 goarch: arm64 106 - goos: openbsd 107 goarch: arm 108 goarm: 7 109 env: 110 GOOS: ${{ matrix.goos }} 111 GOARCH: ${{ matrix.goarch }} 112 GOARM: ${{ matrix.goarm }} 113 GOMIPS: ${{ matrix.gomips }} 114 CGO_ENABLED: 0 115 steps: 116 - name: Checkout codebase 117 uses: actions/checkout@v4 118 - name: Show workflow information 119 run: | 120 if [ ! -z $GOARM ]; then 121 export GOARM=v$GOARM 122 fi 123 export _NAME="nexttrace_${GOOS}_${GOARCH}${GOARM}" 124 if [ "$GOOS" == "windows" ]; then 125 export _NAME="$_NAME.exe" 126 fi 127 if [ "$GOMIPS" == "softfloat" ]; then 128 export _NAME="${_NAME}_softfolat" 129 fi 130 echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME" 131 echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV 132 echo "BUILD_VERSION=$(git describe --tags --always)" >> $GITHUB_ENV 133 echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV 134 echo "COMMIT_SHA1=$(git rev-parse --short HEAD)" >> $GITHUB_ENV 135 - name: Set up Go 136 uses: actions/setup-go@v5 137 with: 138 go-version: '1.22' 139 - name: Get project dependencies 140 run: go mod download 141 - name: Build 142 run: | 143 go build -trimpath -o dist/${ASSET_NAME} \ 144 -ldflags "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \ 145 -X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \ 146 -X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\ 147 -w -s" 148 - name: Upload files to Artifacts 149 uses: actions/upload-artifact@v4 150 with: 151 name: ${{ env.ASSET_NAME }} 152 path: | 153 dist/${{ env.ASSET_NAME }} 154 - name: Release 155 if: startsWith(github.ref, 'refs/tags/v') 156 uses: softprops/action-gh-release@v2 157 with: # 将下述可执行文件 release 上去 158 draft: true # Release草稿 159 files: | 160 dist/* 161 env: 162 GITHUB_TOKEN: ${{ secrets.GT_Token }} 163 164 publish-new-formula: 165 needs: build 166 # The type of runner that the job will run on 167 runs-on: ubuntu-latest 168 if: startsWith(github.ref, 'refs/tags/v') 169 170 # Steps represent a sequence of tasks that will be executed as part of the job 171 steps: 172 # Runs a single command using the runners shell 173 - name: config git 174 run: | 175 git config --global user.email "${{ secrets.git_mail }}" 176 git config --global user.name "${{ secrets.git_name }}" 177 - name: Clone repo 178 run: | 179 git clone https://github.com/nxtrace/homebrew-nexttrace.git 180 - name: Exec scipt 181 run: | 182 cd homebrew-nexttrace 183 bash genFormula.sh 184 # - name: setup SSH keys and known_hosts 185 # run: | 186 # mkdir -p ~/.ssh 187 # ssh-keyscan github.com >> ~/.ssh/known_hosts 188 # ssh-agent -a $SSH_AUTH_SOCK > /dev/null 189 # ssh-add - <<< "${{ secrets.ID_RSA }}" 190 # env: 191 # SSH_AUTH_SOCK: /tmp/ssh_agent.sock 192 - name: Git Push 193 run: | 194 cd homebrew-nexttrace 195 git commit -am 'Publish a new version with Formula' || true 196 git remote set-url origin https://${{ secrets.gt_token }}@github.com/nxtrace/homebrew-nexttrace.git 197 git push 198 # env: 199 # SSH_AUTH_SOCK: /tmp/ssh_agent.sock 200 - run: echo "🍏 This job's status is ${{ job.status }}."