name: Release on: push: branches: [main] tags: ["v*"] permissions: contents: write packages: write jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: "1.25" - run: go test ./... binaries: needs: test runs-on: ubuntu-latest strategy: matrix: include: - goos: linux goarch: amd64 - goos: linux goarch: arm64 - goos: darwin goarch: amd64 - goos: darwin goarch: arm64 steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: "1.25" - name: Determine version id: version run: | if [[ "$GITHUB_REF" == refs/tags/v* ]]; then echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" else echo "version=0.1.0-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" fi - name: Build env: CGO_ENABLED: "0" GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} run: | go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o ublproxy . - name: Archive run: tar czf "ublproxy-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz" ublproxy - uses: actions/upload-artifact@v4 with: name: ublproxy-${{ matrix.goos }}-${{ matrix.goarch }} path: "ublproxy-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz" release: needs: binaries runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v4 with: merge-multiple: true - name: Determine version id: version run: | if [[ "$GITHUB_REF" == refs/tags/v* ]]; then echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" echo "prerelease=false" >> "$GITHUB_OUTPUT" else echo "version=0.1.0-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" echo "prerelease=true" >> "$GITHUB_OUTPUT" fi - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: tag_name: ${{ steps.version.outputs.version }} name: ${{ steps.version.outputs.version }} prerelease: ${{ steps.version.outputs.prerelease == 'true' }} generate_release_notes: true files: "*.tar.gz" docker: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Determine version and tags id: meta run: | REPO="ghcr.io/${{ github.repository }}" if [[ "$GITHUB_REF" == refs/tags/v* ]]; then VERSION="${GITHUB_REF#refs/tags/}" MAJOR="${VERSION%%.*}" MINOR="${VERSION%.*}" TAGS="${REPO}:${VERSION},${REPO}:${MINOR},${REPO}:${MAJOR},${REPO}:latest" echo "version=${VERSION}" >> "$GITHUB_OUTPUT" else VERSION="0.1.0-${GITHUB_SHA::7}" TAGS="${REPO}:${VERSION},${REPO}:edge" echo "version=${VERSION}" >> "$GITHUB_OUTPUT" fi echo "tags=${TAGS}" >> "$GITHUB_OUTPUT" - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: docker/build-push-action@v6 with: context: . push: true platforms: linux/amd64,linux/arm64 build-args: VERSION=${{ steps.meta.outputs.version }} tags: ${{ steps.meta.outputs.tags }} cache-from: type=gha cache-to: type=gha,mode=max