summaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
blob: 0c02d042a61cff5b2fa548108e403576c87ea8e1 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: release

on:
  release: # Docs: <https://help.github.com/en/articles/events-that-trigger-workflows#release-event-release>
    types:
      - released
      - prereleased

jobs:
  build:
    name: Build for ${{ matrix.os }} (${{ matrix.arch }}, ${{ matrix.compiler }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        os: [ windows, darwin ] # linux, darwin, windows
        compiler: [ gcc ] # gcc, musl-gcc
        archiver: [ zip ] # tar, zip
        arch: [ amd64 ]   # amd64, 386
        include:
          - os: linux
            compiler: gcc
            archiver: tar
            arch: amd64
            # -----
          - os: linux
            compiler: gcc
            archiver: tar
            arch: arm64
            # -----
          - os: darwin
            compiler: gcc
            archiver: tar
            arch: arm64
            # -----
          - os: freebsd
            compiler: gcc
            archiver: tar
            arch: amd64
            # -----
          - os: ''
            compiler: musl-gcc # more info: <https://musl.libc.org/>
            archiver: tar
            arch: amd64
    steps:
      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: stable

      - name: Check out code
        uses: actions/checkout@v4

      - name: Install musl
        if: matrix.compiler == 'musl-gcc'
        run: sudo apt-get install -y musl-tools

      - name: Download dependencies
        run: go mod download # `-x` means "verbose" mode

      - name: Generate builder values
        id: values
        run: |
          echo "version=$(echo ${GITHUB_REF##*/} | sed -e 's/^[vV ]*//')" >> $GITHUB_OUTPUT
          echo "timestamp=$(echo $(date +%FT%T%z))" >> $GITHUB_OUTPUT
          echo "binary-name=$(echo $(echo rr`[ ${{ matrix.os }} = 'windows' ] && echo '.exe'`))" >> $GITHUB_OUTPUT
          if [ ${{ matrix.os }} == "windows" ]; then
            echo "sign-cert-name=rr.exe.asc" >> $GITHUB_OUTPUT
          else
            echo "sign-cert-name=rr.asc" >> $GITHUB_OUTPUT
          fi

      - name: Import GPG key
        uses: crazy-max/ghaction-import-gpg@v6
        with:
          gpg_private_key: ${{ secrets.GPG_SIGNING_KEY }}
          passphrase: ${{ secrets.GPG_PASS }}
          git_user_signingkey: true
          git_commit_gpgsign: false

      - name: Compile binary file
        env:
          GOOS: ${{ matrix.os }}
          GOARCH: ${{ matrix.arch }}
          CC: ${{ matrix.compiler }}
          GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
          GPG_PASS: ${{secrets.GPG_PASS}}
          CGO_ENABLED: 0
          LDFLAGS: >-
            -s
            -X github.com/roadrunner-server/roadrunner/v2024/internal/meta.version=${{ steps.values.outputs.version }}
            -X github.com/roadrunner-server/roadrunner/v2024/internal/meta.buildTime=${{ steps.values.outputs.timestamp }}
        run: |
          go build -pgo=roadrunner.pprof -trimpath -ldflags "$LDFLAGS" -o "./${{ steps.values.outputs.binary-name }}" ./cmd/rr
          stat "./${{ steps.values.outputs.binary-name }}"
          gpg --detach-sign --armor "./${{ steps.values.outputs.binary-name }}"

      - name: Generate distributive directory name
        id: dist-dir
        run: >
          echo "name=$(echo roadrunner-${{ steps.values.outputs.version }}-$(
            [ ${{ matrix.os }} != '' ] && echo '${{ matrix.os }}' || echo 'unknown'
          )$(
            [ ${{ matrix.compiler }} = 'musl-gcc' ] && echo '-musl'
          ))-${{ matrix.arch }}" >> $GITHUB_OUTPUT

      - name: Generate distributive archive name
        id: dist-arch
        run: >
          echo "name=$(echo ${{ steps.dist-dir.outputs.name }}.$(
            case ${{ matrix.archiver }} in
              zip) echo 'zip';;
              tar) echo 'tar.gz';;
              *)   exit 10;
            esac
          ))" >> $GITHUB_OUTPUT

      - name: Create distributive
        run: |
          mkdir ${{ steps.dist-dir.outputs.name }}
          mv "./${{ steps.values.outputs.binary-name }}"  "./${{ steps.values.outputs.sign-cert-name }}" ./${{ steps.dist-dir.outputs.name }}/
          cp  ./README.md ./CHANGELOG.md ./LICENSE ./${{ steps.dist-dir.outputs.name }}

      - name: Pack distributive using tar
        if: matrix.archiver == 'tar'
        run: tar -zcf "${{ steps.dist-arch.outputs.name }}" "${{ steps.dist-dir.outputs.name }}"

      - name: Pack distributive using zip
        if: matrix.archiver == 'zip'
        run: zip -r -q "${{ steps.dist-arch.outputs.name }}" "${{ steps.dist-dir.outputs.name }}"

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ steps.dist-dir.outputs.name }}
          path: ${{ steps.dist-arch.outputs.name }}
          if-no-files-found: error
          retention-days: 30

      - name: Upload binaries to release
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: ${{ steps.dist-arch.outputs.name }}
          asset_name: ${{ steps.dist-arch.outputs.name }}
          tag: ${{ github.ref }}

  docker:
    name: Build docker image
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v4

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3 # Action page: <https://github.com/docker/setup-qemu-action>

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3 # Action page: <https://github.com/docker/setup-buildx-action>

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_LOGIN }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ secrets.GHCR_LOGIN }}
          password: ${{ secrets.GHCR_PASSWORD }}

      - name: Generate builder values
        id: values
        run: |
          echo "version_full=$(echo ${GITHUB_REF##*/} | sed -e 's/^[vV ]*//')" >> $GITHUB_OUTPUT
          echo "timestamp=$(echo $(date +%FT%T%z))" >> $GITHUB_OUTPUT

      - name: Build image
        uses: docker/build-push-action@v6 # Action page: <https://github.com/docker/build-push-action>
        with:
          context: .
          file: Dockerfile
          push: true
          platforms: linux/amd64,linux/arm64
          build-args: |
            APP_VERSION=${{ steps.values.outputs.version_full}}
            BUILD_TIME=${{ steps.values.outputs.timestamp }}
          tags: |
            spiralscout/roadrunner:${{ steps.values.outputs.version_full}}
            spiralscout/roadrunner:latest
            spiralscout/roadrunner:2024
            spiralscout/roadrunner:2024.3

            ghcr.io/roadrunner-server/roadrunner:${{ steps.values.outputs.version_full}}
            ghcr.io/roadrunner-server/roadrunner:latest
            ghcr.io/roadrunner-server/roadrunner:2024
            ghcr.io/roadrunner-server/roadrunner:2024.3