Build and Release #8
Workflow file for this run
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: Build and Release | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| release: | |
| types: [ published ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| id-token: write | |
| attestations: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.21' | |
| cache: true | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Run tests | |
| run: | | |
| go test -v ./... | |
| go vet ./... | |
| - name: Build binary | |
| run: | | |
| go build -ldflags="-w -s" -o tsflow . | |
| chmod +x tsflow | |
| - name: Build multi-platform binaries | |
| if: github.event_name == 'release' | |
| run: | | |
| GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o tsflow-linux-amd64 . | |
| GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o tsflow-linux-arm64 . | |
| GOOS=darwin GOARCH=amd64 go build -ldflags="-w -s" -o tsflow-darwin-amd64 . | |
| GOOS=darwin GOARCH=arm64 go build -ldflags="-w -s" -o tsflow-darwin-arm64 . | |
| GOOS=windows GOARCH=amd64 go build -ldflags="-w -s" -o tsflow-windows-amd64.exe . | |
| chmod +x tsflow-* | |
| - name: Set up Docker Buildx | |
| if: github.event_name != 'pull_request' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Convert repository name to lowercase | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| echo "IMAGE_NAME_LOWER=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV} | |
| - name: Log in to Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GH_TOKEN }} | |
| - name: Build and push Docker image | |
| if: github.event_name != 'pull_request' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:${{ github.sha }} | |
| labels: | | |
| org.opencontainers.image.source=${{ github.event.repository.html_url }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Make package public | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| # Wait a moment for the package to be fully created | |
| sleep 10 | |
| # Get package info and make it public | |
| PACKAGE_NAME=$(echo "${{ env.IMAGE_NAME_LOWER }}" | cut -d'/' -f2) | |
| curl -X PATCH \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/user/packages/container/${PACKAGE_NAME} \ | |
| -d '{"visibility":"public"}' || echo "Package may already be public or error occurred" | |
| - name: Create release archives | |
| if: github.event_name == 'release' | |
| run: | | |
| tar -czf tsflow-linux-amd64.tar.gz tsflow-linux-amd64 | |
| tar -czf tsflow-linux-arm64.tar.gz tsflow-linux-arm64 | |
| tar -czf tsflow-darwin-amd64.tar.gz tsflow-darwin-amd64 | |
| tar -czf tsflow-darwin-arm64.tar.gz tsflow-darwin-arm64 | |
| zip tsflow-windows-amd64.zip tsflow-windows-amd64.exe | |
| sha256sum *.tar.gz *.zip > checksums.txt | |
| - name: Upload release assets | |
| if: github.event_name == 'release' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| *.tar.gz | |
| *.zip | |
| checksums.txt | |
| body: | | |
| ## TSFlow ${{ github.ref_name }} | |
| ### Docker Installation | |
| ```bash | |
| docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest | |
| docker run -p 8080:8080 \ | |
| -e TAILSCALE_ACCESS_TOKEN="your-token" \ | |
| -e TAILSCALE_TAILNET="your-tailnet" \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest | |
| ``` | |
| ### Binary Installation | |
| Download the appropriate binary for your platform from the assets below. | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |