summaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
blob: cd87d19e1ed28095ddc01bc5bf253198a318e426 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Release

on:
  push:
    tags:
      - 'v*'

jobs:
  build:
    name: Build release binaries
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: linux/amd64
            ext: tar.gz
            runs_on: ubuntu-latest

          - target: linux/arm64
            ext: tar.gz
            runs_on: ubuntu-latest

          - target: linux/386
            ext: tar.gz
            runs_on: ubuntu-latest

          - target: linux/arm
            ext: tar.gz
            runs_on: ubuntu-latest

          - target: windows/amd64
            ext: zip
            runs_on: windows-latest

          - target: windows/386
            ext: zip
            runs_on: windows-latest

          - target: windows/arm64
            ext: zip
            runs_on: windows-latest

          - target: darwin/amd64
            ext: tar.gz
            runs_on: macos-latest

          - target: darwin/arm64
            ext: tar.gz
            runs_on: macos-latest

    runs-on: ${{ matrix.runs_on }}
    steps:
      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: stable

      - name: Package on Windows (PowerShell)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          $GOARCH = "${{ matrix.target.split('/')[1] }}"
          $GOOS   = "windows"
          $BIN    = "eko.exe"
          $DEST   = "dist/eko-${GOARCH}-$GOOS.zip"

          # Maybe: Compress-Archive -Path $BIN or use Get-ChildItem
          Compress-Archive -LiteralPath $BIN -DestinationPath $DEST

          # Compute SHA256 checksum – via built-in command or external tool if missing
          if (Get-Command shasum -ErrorAction SilentlyContinue) {
            shasum -a 256 $DEST | Out-File "$DEST.sha256" -Encoding ascii
          } else {
            # fallback: use PowerShell's Get-FileHash
            $hash = (Get-FileHash $DEST -Algorithm SHA256).Hash
            "$hash  $(Split-Path $DEST -Leaf)" | Out-File "$DEST.sha256"
          }

      - name: Build binary
        if: runner.os != 'Windows'
        shell: bash
        run: |
          TARGET="${{ matrix.target }}"
          GOOS=$(echo "$TARGET" | cut -d'/' -f1)
          GOARCH=$(echo "$TARGET" | cut -d'/' -f2)
          BIN=eko
          EXT=""
          if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi

          mkdir -p dist
          env GOOS=$GOOS GOARCH=$GOARCH go build -o $BIN$EXT ./cmd/client

          ARCHIVE=dist/${BIN}-${GOARCH}-${GOOS}.${{ matrix.ext }}

          if [ "${{ matrix.ext }}" = "zip" ]; then
            zip -j $ARCHIVE $BIN$EXT
          else
            tar -czf $ARCHIVE $BIN$EXT
          fi

          shasum -a 256 $ARCHIVE > $ARCHIVE.sha256

      - name: Upload release artifacts
        uses: softprops/action-gh-release@v2
        with:
          token: ${{ secrets.EKO_RELEASE_TOKEN }}
          tag_name: ${{ github.ref_name }}
          files: dist/*