|
| 1 | +name: Make Prebuilds |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - 'master' |
| 6 | + paths: |
| 7 | + - '.github/workflows/prebuild.yaml' |
| 8 | + |
| 9 | +# When a new Node.js version is released or for any other reason that a build |
| 10 | +# needs to be triggered, amend this file and force-push. |
| 11 | + |
| 12 | +env: |
| 13 | + # These should generally be the same: |
| 14 | + CANVAS_VERSION_TO_BUILD: "2.6.1" # no "v" prefix. TODO switch to $GITHUB_REF if we switch to `on: release` |
| 15 | + CANVAS_PREBUILT_VERSION: "2.6.1" |
| 16 | + |
| 17 | +jobs: |
| 18 | + Linux: |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + # Make sure to set this for the other builds also! |
| 22 | + node: [8, 9, 10, 11, 12, 13, 14] |
| 23 | + name: Node.js ${{ matrix.node }} on Linux |
| 24 | + runs-on: ubuntu-latest |
| 25 | + container: |
| 26 | + image: chearon/canvas-prebuilt:7 |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v2 |
| 29 | + |
| 30 | + - uses: actions/setup-node@v1 |
| 31 | + with: |
| 32 | + node-version: ${{ matrix.node }} |
| 33 | + |
| 34 | + - name: Build |
| 35 | + env: |
| 36 | + OS: ${{ runner.os }} |
| 37 | + run: | |
| 38 | + npm install -g node-gyp |
| 39 | + npm install --ignore-scripts |
| 40 | + . prebuild/$OS/preinstall.sh |
| 41 | + cp prebuild/$OS/binding.gyp binding.gyp |
| 42 | + node-gyp rebuild -j 2 |
| 43 | + . prebuild/$OS/bundle.sh |
| 44 | +
|
| 45 | + - name: Test binary |
| 46 | + run: node -e "require('.')" |
| 47 | + |
| 48 | + - name: Make bundle |
| 49 | + id: make_bundle |
| 50 | + run: . prebuild/tarball.sh |
| 51 | + |
| 52 | + - name: Upload |
| 53 | + |
| 54 | + with: |
| 55 | + script: | |
| 56 | + const fs = require("fs"); |
| 57 | + const assetName = "${{ steps.make_bundle.outputs.asset_name }}"; |
| 58 | + const tagName = `v${process.env.CANVAS_PREBUILT_VERSION}`; |
| 59 | +
|
| 60 | + const releases = await github.repos.listReleases({ |
| 61 | + owner: process.env.GITHUB_REPOSITORY.split("/")[0], |
| 62 | + repo: process.env.GITHUB_REPOSITORY.split("/")[1] |
| 63 | + }); |
| 64 | + const release = releases.data.find(r => r.tag_name === tagName); |
| 65 | +
|
| 66 | + for (const asset of release.assets) { |
| 67 | + if (asset.name === assetName) { |
| 68 | + await github.repos.deleteReleaseAsset({ |
| 69 | + owner: process.env.GITHUB_REPOSITORY.split("/")[0], |
| 70 | + repo: process.env.GITHUB_REPOSITORY.split("/")[1], |
| 71 | + asset_id: asset.id |
| 72 | + }); |
| 73 | + break; |
| 74 | + } |
| 75 | + } |
| 76 | +
|
| 77 | + // (This is equivalent to actions/upload-release-asset. We're |
| 78 | + // already in a script, so might as well do it here.) |
| 79 | + const r = await github.repos.uploadReleaseAsset({ |
| 80 | + url: release.upload_url, |
| 81 | + headers: { |
| 82 | + "content-type": "application/x-gzip", |
| 83 | + "content-length": `${fs.statSync(assetName).size}` |
| 84 | + }, |
| 85 | + name: assetName, |
| 86 | + data: fs.readFileSync(assetName) |
| 87 | + }); |
| 88 | +
|
| 89 | + macOS: |
| 90 | + strategy: |
| 91 | + matrix: |
| 92 | + node: [8, 9, 10, 11, 12, 13, 14] |
| 93 | + name: Node.js ${{ matrix.node }} on macOS |
| 94 | + runs-on: macos-latest |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@v2 |
| 97 | + |
| 98 | + - uses: actions/setup-node@v1 |
| 99 | + with: |
| 100 | + node-version: ${{ matrix.node }} |
| 101 | + |
| 102 | + - name: Build |
| 103 | + env: |
| 104 | + OS: ${{ runner.os }} |
| 105 | + run: | |
| 106 | + npm install -g node-gyp |
| 107 | + npm install --ignore-scripts |
| 108 | + . prebuild/$OS/preinstall.sh |
| 109 | + cp prebuild/$OS/binding.gyp binding.gyp |
| 110 | + node-gyp rebuild -j 2 |
| 111 | + . prebuild/$OS/bundle.sh |
| 112 | +
|
| 113 | + - name: Test binary |
| 114 | + run: node -e "require('.')" |
| 115 | + |
| 116 | + - name: Make bundle |
| 117 | + id: make_bundle |
| 118 | + run: . prebuild/tarball.sh |
| 119 | + |
| 120 | + - name: Upload |
| 121 | + |
| 122 | + with: |
| 123 | + script: | |
| 124 | + const fs = require("fs"); |
| 125 | + const assetName = "${{ steps.make_bundle.outputs.asset_name }}"; |
| 126 | + const tagName = `v${process.env.CANVAS_PREBUILT_VERSION}`; |
| 127 | +
|
| 128 | + const releases = await github.repos.listReleases({ |
| 129 | + owner: process.env.GITHUB_REPOSITORY.split("/")[0], |
| 130 | + repo: process.env.GITHUB_REPOSITORY.split("/")[1] |
| 131 | + }); |
| 132 | + const release = releases.data.find(r => r.tag_name === tagName); |
| 133 | +
|
| 134 | + for (const asset of release.assets) { |
| 135 | + if (asset.name === assetName) { |
| 136 | + await github.repos.deleteReleaseAsset({ |
| 137 | + owner: process.env.GITHUB_REPOSITORY.split("/")[0], |
| 138 | + repo: process.env.GITHUB_REPOSITORY.split("/")[1], |
| 139 | + asset_id: asset.id |
| 140 | + }); |
| 141 | + break; |
| 142 | + } |
| 143 | + } |
| 144 | +
|
| 145 | + // (This is equivalent to actions/upload-release-asset. We're |
| 146 | + // already in a script, so might as well do it here.) |
| 147 | + const r = await github.repos.uploadReleaseAsset({ |
| 148 | + url: release.upload_url, |
| 149 | + headers: { |
| 150 | + "content-type": "application/x-gzip", |
| 151 | + "content-length": `${fs.statSync(assetName).size}` |
| 152 | + }, |
| 153 | + name: assetName, |
| 154 | + data: fs.readFileSync(assetName) |
| 155 | + }); |
| 156 | +
|
| 157 | + Win: |
| 158 | + strategy: |
| 159 | + matrix: |
| 160 | + node: [8, 9, 10, 11, 12, 13, 14] |
| 161 | + name: Node.js ${{ matrix.node }} on Windows |
| 162 | + runs-on: windows-latest |
| 163 | + steps: |
| 164 | + # TODO drop when https://github.com/actions/virtual-environments/pull/632 lands |
| 165 | + - uses: numworks/setup-msys2@v1 |
| 166 | + with: |
| 167 | + update: true |
| 168 | + path-type: inherit |
| 169 | + |
| 170 | + - uses: actions/setup-node@v1 |
| 171 | + with: |
| 172 | + node-version: ${{ matrix.node }} |
| 173 | + |
| 174 | + - uses: actions/checkout@v2 |
| 175 | + |
| 176 | + - name: Setup |
| 177 | + run: | |
| 178 | + msys2do npm install -g node-gyp |
| 179 | + msys2do npm install --ignore-scripts |
| 180 | + msys2do . prebuild/Windows/preinstall.sh |
| 181 | +
|
| 182 | + - name: Build |
| 183 | + run: | |
| 184 | + msys2do cp prebuild/Windows/binding.gyp binding.gyp |
| 185 | + msys2do node-gyp configure |
| 186 | + msys2do node-gyp rebuild -j 2 |
| 187 | +
|
| 188 | + - name: Bundle |
| 189 | + run: msys2do . prebuild/Windows/bundle.sh |
| 190 | + |
| 191 | + - name: Test binary |
| 192 | + run: node -e "require('.')" |
| 193 | + |
| 194 | + - name: Make asset |
| 195 | + id: make_bundle |
| 196 | + # I can't figure out why this isn't an env var already. It shows up with `env`. |
| 197 | + run: msys2do CANVAS_PREBUILT_VERSION=${{ env.CANVAS_PREBUILT_VERSION }} . prebuild/tarball.sh |
| 198 | + |
| 199 | + - name: Upload |
| 200 | + |
| 201 | + with: |
| 202 | + script: | |
| 203 | + const fs = require("fs"); |
| 204 | + const assetName = "${{ steps.make_bundle.outputs.asset_name }}"; |
| 205 | + const tagName = `v${process.env.CANVAS_PREBUILT_VERSION}`; |
| 206 | +
|
| 207 | + const releases = await github.repos.listReleases({ |
| 208 | + owner: process.env.GITHUB_REPOSITORY.split("/")[0], |
| 209 | + repo: process.env.GITHUB_REPOSITORY.split("/")[1] |
| 210 | + }); |
| 211 | + const release = releases.data.find(r => r.tag_name === tagName); |
| 212 | +
|
| 213 | + for (const asset of release.assets) { |
| 214 | + if (asset.name === assetName) { |
| 215 | + await github.repos.deleteReleaseAsset({ |
| 216 | + owner: process.env.GITHUB_REPOSITORY.split("/")[0], |
| 217 | + repo: process.env.GITHUB_REPOSITORY.split("/")[1], |
| 218 | + asset_id: asset.id |
| 219 | + }); |
| 220 | + break; |
| 221 | + } |
| 222 | + } |
| 223 | +
|
| 224 | + // (This is equivalent to actions/upload-release-asset. We're |
| 225 | + // already in a script, so might as well do it here.) |
| 226 | + const r = await github.repos.uploadReleaseAsset({ |
| 227 | + url: release.upload_url, |
| 228 | + headers: { |
| 229 | + "content-type": "application/x-gzip", |
| 230 | + "content-length": `${fs.statSync(assetName).size}` |
| 231 | + }, |
| 232 | + name: assetName, |
| 233 | + data: fs.readFileSync(assetName) |
| 234 | + }); |
0 commit comments