|
| 1 | +name: Auto Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + - 'v[0-9]+.[0-9]+.[0-9]+-*' |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + create-release: |
| 14 | + name: Create Release |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + outputs: |
| 18 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 19 | + tag_name: ${{ steps.get_tag.outputs.tag }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Get tag |
| 28 | + id: get_tag |
| 29 | + run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 30 | + |
| 31 | + - name: Generate changelog |
| 32 | + id: changelog |
| 33 | + run: | |
| 34 | + # Get the previous tag |
| 35 | + PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") |
| 36 | + |
| 37 | + if [ -z "$PREV_TAG" ]; then |
| 38 | + echo "changelog=Initial release" >> $GITHUB_OUTPUT |
| 39 | + else |
| 40 | + # Generate changelog between tags |
| 41 | + CHANGELOG=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD | head -20) |
| 42 | + echo "changelog<<EOF" >> $GITHUB_OUTPUT |
| 43 | + echo "$CHANGELOG" >> $GITHUB_OUTPUT |
| 44 | + echo "EOF" >> $GITHUB_OUTPUT |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Create Release |
| 48 | + id: create_release |
| 49 | + uses: actions/create-release@v1 |
| 50 | + env: |
| 51 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + with: |
| 53 | + tag_name: ${{ steps.get_tag.outputs.tag }} |
| 54 | + release_name: Release ${{ steps.get_tag.outputs.tag }} |
| 55 | + body: | |
| 56 | + ## Changes in ${{ steps.get_tag.outputs.tag }} |
| 57 | + |
| 58 | + ${{ steps.changelog.outputs.changelog }} |
| 59 | + |
| 60 | + ## Downloads |
| 61 | + |
| 62 | + Choose the appropriate binary for your platform below. |
| 63 | + |
| 64 | + ### Installation Instructions |
| 65 | + |
| 66 | + 1. Download the appropriate binary for your platform |
| 67 | + 2. Extract the archive if needed |
| 68 | + 3. Move the binary to a directory in your PATH |
| 69 | + 4. Make it executable (Linux/macOS): `chmod +x tunn` |
| 70 | + |
| 71 | + ### Verification |
| 72 | + |
| 73 | + All binaries are signed and can be verified using the provided checksums. |
| 74 | + draft: false |
| 75 | + prerelease: ${{ contains(steps.get_tag.outputs.tag, '-') }} |
| 76 | + |
| 77 | + build-and-upload: |
| 78 | + name: Build and Upload Assets |
| 79 | + needs: create-release |
| 80 | + runs-on: ubuntu-latest |
| 81 | + strategy: |
| 82 | + matrix: |
| 83 | + include: |
| 84 | + # Windows |
| 85 | + - os: windows |
| 86 | + arch: amd64 |
| 87 | + goos: windows |
| 88 | + goarch: amd64 |
| 89 | + - os: windows |
| 90 | + arch: 386 |
| 91 | + goos: windows |
| 92 | + goarch: 386 |
| 93 | + - os: windows |
| 94 | + arch: arm64 |
| 95 | + goos: windows |
| 96 | + goarch: arm64 |
| 97 | + |
| 98 | + # Linux |
| 99 | + - os: linux |
| 100 | + arch: amd64 |
| 101 | + goos: linux |
| 102 | + goarch: amd64 |
| 103 | + - os: linux |
| 104 | + arch: 386 |
| 105 | + goos: linux |
| 106 | + goarch: 386 |
| 107 | + - os: linux |
| 108 | + arch: arm64 |
| 109 | + goos: linux |
| 110 | + goarch: arm64 |
| 111 | + - os: linux |
| 112 | + arch: arm |
| 113 | + goos: linux |
| 114 | + goarch: arm |
| 115 | + |
| 116 | + # macOS |
| 117 | + - os: darwin |
| 118 | + arch: amd64 |
| 119 | + goos: darwin |
| 120 | + goarch: amd64 |
| 121 | + - os: darwin |
| 122 | + arch: arm64 |
| 123 | + goos: darwin |
| 124 | + goarch: arm64 |
| 125 | + |
| 126 | + # FreeBSD |
| 127 | + - os: freebsd |
| 128 | + arch: amd64 |
| 129 | + goos: freebsd |
| 130 | + goarch: amd64 |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Checkout code |
| 134 | + uses: actions/checkout@v4 |
| 135 | + |
| 136 | + - name: Set up Go |
| 137 | + uses: actions/setup-go@v5 |
| 138 | + with: |
| 139 | + go-version: '1.21' |
| 140 | + |
| 141 | + - name: Build binary |
| 142 | + env: |
| 143 | + GOOS: ${{ matrix.goos }} |
| 144 | + GOARCH: ${{ matrix.goarch }} |
| 145 | + run: | |
| 146 | + binary_name="tunn" |
| 147 | + if [ "${{ matrix.goos }}" = "windows" ]; then |
| 148 | + binary_name="${binary_name}.exe" |
| 149 | + fi |
| 150 | + |
| 151 | + # Build with version info |
| 152 | + go build -ldflags="-s -w -X main.Version=${{ needs.create-release.outputs.tag_name }}" -o "${binary_name}" . |
| 153 | + |
| 154 | + # Create archive |
| 155 | + if [ "${{ matrix.goos }}" = "windows" ]; then |
| 156 | + zip "tunn-${{ matrix.os }}-${{ matrix.arch }}.zip" "${binary_name}" |
| 157 | + echo "ASSET_NAME=tunn-${{ matrix.os }}-${{ matrix.arch }}.zip" >> $GITHUB_ENV |
| 158 | + echo "ASSET_PATH=tunn-${{ matrix.os }}-${{ matrix.arch }}.zip" >> $GITHUB_ENV |
| 159 | + else |
| 160 | + tar -czf "tunn-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" "${binary_name}" |
| 161 | + echo "ASSET_NAME=tunn-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" >> $GITHUB_ENV |
| 162 | + echo "ASSET_PATH=tunn-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" >> $GITHUB_ENV |
| 163 | + fi |
| 164 | +
|
| 165 | + - name: Upload Release Asset |
| 166 | + uses: actions/upload-release-asset@v1 |
| 167 | + env: |
| 168 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 169 | + with: |
| 170 | + upload_url: ${{ needs.create-release.outputs.upload_url }} |
| 171 | + asset_path: ${{ env.ASSET_PATH }} |
| 172 | + asset_name: ${{ env.ASSET_NAME }} |
| 173 | + asset_content_type: application/octet-stream |
| 174 | + |
| 175 | + generate-checksums: |
| 176 | + name: Generate Checksums |
| 177 | + needs: [create-release, build-and-upload] |
| 178 | + runs-on: ubuntu-latest |
| 179 | + |
| 180 | + steps: |
| 181 | + - name: Download release assets |
| 182 | + run: | |
| 183 | + # Download all assets from the release |
| 184 | + mkdir -p assets |
| 185 | + cd assets |
| 186 | + |
| 187 | + # Get release info |
| 188 | + RELEASE_ID=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ needs.create-release.outputs.tag_name }}" | jq -r '.id') |
| 189 | + |
| 190 | + # Download all assets |
| 191 | + curl -s "https://api.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" | \ |
| 192 | + jq -r '.[].browser_download_url' | \ |
| 193 | + while read url; do |
| 194 | + curl -L -O "$url" |
| 195 | + done |
| 196 | +
|
| 197 | + - name: Generate checksums |
| 198 | + run: | |
| 199 | + cd assets |
| 200 | + sha256sum * > checksums.txt |
| 201 | + cat checksums.txt |
| 202 | +
|
| 203 | + - name: Upload checksums |
| 204 | + uses: actions/upload-release-asset@v1 |
| 205 | + env: |
| 206 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 207 | + with: |
| 208 | + upload_url: ${{ needs.create-release.outputs.upload_url }} |
| 209 | + asset_path: assets/checksums.txt |
| 210 | + asset_name: checksums.txt |
| 211 | + asset_content_type: text/plain |
0 commit comments