|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-release-assets: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + include: |
| 18 | + - goos: linux |
| 19 | + goarch: amd64 |
| 20 | + archive: tar.gz |
| 21 | + - goos: linux |
| 22 | + goarch: arm64 |
| 23 | + archive: tar.gz |
| 24 | + - goos: darwin |
| 25 | + goarch: amd64 |
| 26 | + archive: tar.gz |
| 27 | + - goos: darwin |
| 28 | + goarch: arm64 |
| 29 | + archive: tar.gz |
| 30 | + - goos: windows |
| 31 | + goarch: amd64 |
| 32 | + archive: zip |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Setup Node.js |
| 39 | + uses: actions/setup-node@v4 |
| 40 | + with: |
| 41 | + node-version: "20" |
| 42 | + |
| 43 | + - name: Setup pnpm |
| 44 | + uses: pnpm/action-setup@v4 |
| 45 | + with: |
| 46 | + version: 10 |
| 47 | + |
| 48 | + - name: Setup Go |
| 49 | + uses: actions/setup-go@v5 |
| 50 | + with: |
| 51 | + go-version-file: go.mod |
| 52 | + |
| 53 | + - name: Install frontend dependencies |
| 54 | + working-directory: web |
| 55 | + run: pnpm install --frozen-lockfile |
| 56 | + |
| 57 | + - name: Build frontend |
| 58 | + working-directory: web |
| 59 | + run: pnpm build |
| 60 | + |
| 61 | + - name: Build binary |
| 62 | + env: |
| 63 | + CGO_ENABLED: "0" |
| 64 | + GOOS: ${{ matrix.goos }} |
| 65 | + GOARCH: ${{ matrix.goarch }} |
| 66 | + run: | |
| 67 | + mkdir -p dist |
| 68 | + BINARY_NAME=speedtest-next |
| 69 | + if [ "${{ matrix.goos }}" = "windows" ]; then |
| 70 | + BINARY_NAME=speedtest-next.exe |
| 71 | + fi |
| 72 | + go build -o "dist/${BINARY_NAME}" . |
| 73 | +
|
| 74 | + - name: Package tar.gz |
| 75 | + if: matrix.archive == 'tar.gz' |
| 76 | + run: | |
| 77 | + VERSION="${GITHUB_REF_NAME}" |
| 78 | + PACKAGE="speedtest-next_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz" |
| 79 | + tar -C dist -czf "$PACKAGE" . |
| 80 | + echo "PACKAGE=$PACKAGE" >> "$GITHUB_ENV" |
| 81 | +
|
| 82 | + - name: Package zip |
| 83 | + if: matrix.archive == 'zip' |
| 84 | + run: | |
| 85 | + VERSION="${GITHUB_REF_NAME}" |
| 86 | + PACKAGE="speedtest-next_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}.zip" |
| 87 | + cd dist |
| 88 | + zip -r "../$PACKAGE" . |
| 89 | + cd .. |
| 90 | + echo "PACKAGE=$PACKAGE" >> "$GITHUB_ENV" |
| 91 | +
|
| 92 | + - name: Upload release asset |
| 93 | + uses: softprops/action-gh-release@v2 |
| 94 | + with: |
| 95 | + files: ${{ env.PACKAGE }} |
| 96 | + |
| 97 | + docker-image: |
| 98 | + runs-on: ubuntu-latest |
| 99 | + steps: |
| 100 | + - name: Checkout |
| 101 | + uses: actions/checkout@v4 |
| 102 | + |
| 103 | + - name: Set up QEMU |
| 104 | + uses: docker/setup-qemu-action@v3 |
| 105 | + |
| 106 | + - name: Set up Docker Buildx |
| 107 | + uses: docker/setup-buildx-action@v3 |
| 108 | + |
| 109 | + - name: Log in to Docker Hub |
| 110 | + uses: docker/login-action@v3 |
| 111 | + with: |
| 112 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 113 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 114 | + |
| 115 | + - name: Extract Docker metadata |
| 116 | + id: meta |
| 117 | + uses: docker/metadata-action@v5 |
| 118 | + with: |
| 119 | + images: taurusxin/speedtest-next |
| 120 | + tags: | |
| 121 | + type=ref,event=tag |
| 122 | + type=raw,value=latest |
| 123 | +
|
| 124 | + - name: Build and push Docker image |
| 125 | + uses: docker/build-push-action@v6 |
| 126 | + with: |
| 127 | + context: . |
| 128 | + file: ./Dockerfile |
| 129 | + platforms: linux/amd64,linux/arm64 |
| 130 | + push: true |
| 131 | + tags: ${{ steps.meta.outputs.tags }} |
| 132 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments