Upgrade download-artifact action from v3 to v4 in GitHub Actions work… #3
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: rajsinghtech/tsflow | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.21' | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Run tests | |
| run: go test -v ./... | |
| - name: Run go vet | |
| run: go vet ./... | |
| build: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.21' | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Build binaries | |
| run: | | |
| # Build for multiple platforms | |
| 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 . | |
| # Make them executable | |
| chmod +x tsflow-* | |
| - 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: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - 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: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Upload binaries as artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: tsflow-binaries | |
| path: | | |
| tsflow-* | |
| retention-days: 30 | |
| release: | |
| if: github.event_name == 'release' | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: tsflow-binaries | |
| path: ./binaries | |
| - name: Create release archives | |
| run: | | |
| cd binaries | |
| # Create archives for each platform | |
| 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 | |
| # Create checksums | |
| sha256sum *.tar.gz *.zip > checksums.txt | |
| - name: Upload release assets | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| binaries/*.tar.gz | |
| binaries/*.zip | |
| binaries/checksums.txt | |
| body: | | |
| ## TSFlow ${{ github.ref_name }} | |
| ### Installation | |
| #### Docker | |
| ```bash | |
| docker pull ghcr.io/rajsinghtech/tsflow:${{ github.ref_name }} | |
| docker run -p 8080:8080 \ | |
| -e TAILSCALE_ACCESS_TOKEN="your-token" \ | |
| -e TAILSCALE_TAILNET="your-tailnet" \ | |
| ghcr.io/rajsinghtech/tsflow:${{ github.ref_name }} | |
| ``` | |
| #### Binary Download | |
| Download the appropriate binary for your platform from the assets below. | |
| ### Checksums | |
| Verify your download with the provided checksums.txt file. | |
| draft: false | |
| prerelease: false | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} |