chore: get version from github tag #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Go | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: | |
| - "*.*.*" | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build_on_macos: | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: Install dependencies | |
| run: | | |
| go get golang.org/x/tools/cmd/goimports@latest | |
| go get github.com/golangci/golangci-lint/cmd/golangci-lint@latest | |
| - name: Set version | |
| if: github.ref_type == 'tag' | |
| run: | | |
| sed -i '' 's/version = \"dev\"/version = \"${{ github.ref_name }}\"/' main.go | |
| - name: Lint | |
| run: | | |
| make lint || true | |
| - name: Build | |
| run: | | |
| GOARCH=arm64 go build -ldflags="-s -w" -o mobilectl-arm64 | |
| GOARCH=amd64 go build -ldflags="-s -w" -o mobilectl-amd64 | |
| lipo mobilectl-arm64 mobilectl-amd64 -create -output mobilectl-darwin | |
| rm mobilectl-arm64 mobilectl-amd64 | |
| ./mobilectl-darwin --version | |
| - name: Upload macos build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-build | |
| path: | | |
| mobilectl-darwin | |
| retention-days: 1 | |
| overwrite: true | |
| build_on_linux: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: Install dependencies | |
| run: | | |
| go get golang.org/x/tools/cmd/goimports@latest | |
| go get github.com/golangci/golangci-lint/cmd/golangci-lint@latest | |
| - name: Set version | |
| if: github.ref_type == 'tag' | |
| run: | | |
| sed -i 's/version = \"dev\"/version = \"${{ github.ref_name }}\"/' main.go | |
| - name: Build | |
| run: | | |
| GOARCH=arm64 go build -ldflags="-s -w" -o mobilectl-linux-arm64 | |
| GOARCH=amd64 go build -ldflags="-s -w" -o mobilectl-linux-amd64 | |
| ./mobilectl-linux-amd64 --version | |
| - name: Upload macos build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-build | |
| path: | | |
| mobilectl-darwin | |
| mobilectl-linux-arm64 | |
| mobilectl-linux-amd64 | |
| retention-days: 1 | |
| overwrite: true | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: [build_on_linux, build_on_macos] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Upload to GitHub Release | |
| if: github.ref_type == 'tag' | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.RELEASES_TOKEN }} | |
| with: | |
| name: Version ${{ github.ref_name }} | |
| files: | | |
| mobiledeck-${{ github.ref_name }}.vsix | |
| publish: | |
| runs-on: ubuntu-latest | |
| needs: [build_on_linux, build_on_macos] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download darwin build | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: macos-build | |
| path: mobilectl-darwin | |
| - name: Download linux build | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: linux-build | |
| path: mobilectl-linux | |
| - name: Publish | |
| if: github.ref_type == 'tag' | |
| env: | |
| NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
| run: | | |
| # prepare binaries for distribution | |
| mv ./mobilectl-darwin/mobilectl-darwin publish/npm/bin | |
| mv ./mobilectl-linux/mobilectl-linux-amd64 publish/npm/bin | |
| mv ./mobilectl-linux/mobilectl-linux-arm64 publish/npm/bin | |
| chmod +x publish/npm/bin/* | |
| # setup npmrc | |
| echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/.npmrc | |
| # publish to npm | |
| cd publish/npm | |
| sed -i 's/\"local-build\"/\"${{ github.ref_name }}\"/' package.json | |
| npm install | |
| npm publish |