Update README.md #16
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-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 | |
| 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: Zip builds | |
| run: | | |
| mkdir dist | |
| cd dist | |
| # mac | |
| cp ../mobilectl-darwin/mobilectl-darwin mobilectl | |
| zip -9 ../mobilectl-${{ github.ref_name }}-macos.zip mobilectl | |
| rm -f mobilectl | |
| # linux-amd64 | |
| cp ../mobilectl-linux/mobilectl-linux-amd64 mobilectl | |
| zip -9 ../mobilectl-${{ github.ref_name }}-linux-amd64.zip mobilectl | |
| rm -f mobilectl | |
| # linux-arm64 | |
| cp ../mobilectl-linux/mobilectl-linux-arm64 mobilectl | |
| zip -9 ../mobilectl-${{ github.ref_name }}-linux-arm64.zip mobilectl | |
| rm -f mobilectl | |
| cd .. | |
| ls -l *.zip | |
| rm -rf dist | |
| - 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: | | |
| mobilectl-*.zip | |
| - 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 | |
| npm version "${{ github.ref_name }}" --no-git-tag-version | |
| npm install | |
| npm publish |