summaryrefslogtreecommitdiff
path: root/vere/.github/workflows/shared.yml
blob: e13506e239c418869887b1ddff39fadc9f4811dd (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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: shared

on:
  workflow_call:
    inputs:
      pace:
        description: 'Release pace'
        type: string
        default: 'edge'
        required: false
      upload:
        description: 'Upload binaries to GCP'
        type: boolean
        default: false
        required: false
      fake_tests:
        description: 'Run fake ship tests'
        type: boolean
        default: true
        required: false
      next:
        description: 'Next Kelvin version branch name'
        type: string
        default: null
        required: false
    secrets:
      GCP_CREDENTIALS:
        required: false
      GCP_PROJECT:
        required: false

env:
  UPLOAD_BASE: bootstrap.urbit.org/vere
  GH_TOKEN: ${{ github.token }}

jobs:
  urbit:
    strategy:
      fail-fast: false

    runs-on: ubuntu-22.04

    steps:
      #
      # BUILD AND TEST
      #
      - uses: actions/checkout@v3

      - name: Set swap space
        run: |
          echo "Memory and swap:"
          free -h
          echo
          swapon --show
          echo

          export SWAP_FILE=$(swapon --show=NAME | tail -n 1)
          if test -z "${SWAP_FILE}"; then
              export SWAP_FILE=/swapfile
          else
              sudo swapoff -a
              sudo rm "${SWAP_FILE}"
          fi
          sudo fallocate -l 10G "${SWAP_FILE}"
          sudo chmod 600 "${SWAP_FILE}"
          sudo mkswap "${SWAP_FILE}"
          sudo swapon "${SWAP_FILE}"

          echo "Memory and swap:"
          free -h
          echo
          swapon --show
          echo

      - uses: mlugg/setup-zig@v2
        with:
          version: 0.14.1

      - name: Build binaries
        run: |
          if [[ "${{ inputs.pace }}" == "live" ]]; then
            zig build                  \
              -Dall                    \
              -Drelease                \
              --summary all
          else
            zig build                  \
              -Dall                    \
              -Doptimize=ReleaseFast   \
              -Dpace=${{inputs.pace}}  \
              --summary all
          fi
      - name: Run unit tests
        run: |
          zig build                    \
            ur-test ent-test           \
            hashtable-test jets-test   \
            nock-test retrieve-test    \
            serial-test ames-test      \
            pact-test equality-test    \
            boot-test newt-test        \
            vere-noun-test unix-test   \
            benchmarks                 \
            -Doptimize=ReleaseFast     \
            -Dpace=${{inputs.pace}}    \
            --summary all

      - name: Build test binary
        if: ${{ inputs.fake_tests }}
        run: |
          zig build                    \
            -Doptimize=ReleaseFast     \
            -Dpace=${{inputs.pace}}    \
            -Dbinary-name=urbit-test   \
            -Dcpu-dbg                  \
            -Dmem-dbg                  \
            -Dc3dbg                    \
            -Dsnapshot-validation      \
            --summary all

      - name: Boot fake ship
        if: ${{ inputs.fake_tests }}
        env:
          URBIT_BINARY: "zig-out/x86_64-linux-musl/urbit-test"
        run: ./boot-fake-ship.sh

      - name: Run fake ship tests
        if: ${{ inputs.fake_tests }}
        env:
          URBIT_BINARY: "zig-out/x86_64-linux-musl/urbit-test"
        run: ./test-fake-ship.sh

      #
      # UPLOAD TO GCP
      #

      - uses: google-github-actions/auth@v1
        if: ${{ inputs.upload }}
        with:
          credentials_json: ${{ secrets.GCP_CREDENTIALS }}

      - uses: google-github-actions/setup-gcloud@v1
        if: ${{ inputs.upload }}
        with:
          project_id: ${{ secrets.GCP_PROJECT }}

      - name: Upload binary to bootstrap.urbit.org
        if: ${{ inputs.upload }}
        run: |
          sha_version=$(sed -nr 's/#define URBIT_VERSION "(.*)"/\1/p' zig-out/include/version.h)
          declare -a targets=(
            "aarch64-linux-musl linux-aarch64"
            "aarch64-macos-none macos-aarch64"
            "x86_64-linux-musl linux-x86_64"
            "x86_64-macos-none macos-x86_64"
          )
          for t in "${targets[@]}"
          do
            IFS=' ' read zig_target target <<< "${t}"
            urbit_static=$GITHUB_WORKSPACE/zig-out/${zig_target}/urbit
            if ${{ inputs.next != null }}; then
              next=$(echo "${{ inputs.next }}" | sed 's/[^0-9]//g')
              dest="gs://${UPLOAD_BASE}/next/kelvin/${next}/v${sha_version}/vere-v${sha_version}-${target}"
            else
              dest="gs://${UPLOAD_BASE}/${{ inputs.pace }}/v${sha_version}/vere-v${sha_version}-${target}"
            fi

            args=""
            # We never overwrite a binary deployed to the "live" train, but we do
            # overwrite same-versioned binaries deployed to the "soon" and "edge"
            # trains.
            if [[ "${{ inputs.pace }}" == "live" ]]; then
              gsutil cp -n "${urbit_static}" "$dest"
            else
              gsutil cp "${urbit_static}" "$dest"
            fi
            exitcode=$?

            ([ $exitcode -eq 0 ] && echo "upload to $dest complete.") ||
            (echo "upload to $dest failed." && exit $exitcode);
          done

  upload-version-string:
    name: Upload latest deployed version string to GCP
    runs-on: ubuntu-latest
    needs: [urbit]
    if: inputs.upload
    steps:
      - uses: actions/checkout@v3

      - uses: google-github-actions/auth@v1
        with:
          credentials_json: ${{ secrets.GCP_CREDENTIALS }}

      - uses: google-github-actions/setup-gcloud@v1
        with:
          project_id: ${{ secrets.GCP_PROJECT }}

      - name: Upload latest deployed version string to GCP
        run: |
          echo "${{ inputs.pace }}" > ./PACE
          printf $(sed -nr 's/const VERSION = "(.*)"\;/\1/p' build.zig)-%.10s $(git rev-parse HEAD) > ./VERSION

          if ${{ inputs.next != null }}; then
            next=$(echo "${{ inputs.next }}" | sed 's/[^0-9]//g')
            target="gs://${UPLOAD_BASE}/next/kelvin/${next}/last"
          else
            target="gs://${UPLOAD_BASE}/${{ inputs.pace }}/last"
          fi

          # We don't use -n here because we want to overwrite the version
          # string.
          gsutil cp ./VERSION "$target"
          exitcode=$?

          [ $exitcode -eq 0 ] &&
            echo "Upload to $target completed successfully." ||
            echo "Upload to $target failed.";
          exit $exitcode