|
1 | 1 | name: Release |
2 | 2 |
|
3 | 3 | # Publishes one package to npm from its component tag (sync-engine-v1.2.3, |
4 | | -# sync-postgres-v0.4.0). release-please calls this once per package it |
5 | | -# released; re-run it by hand for an existing tag if a run failed — a |
6 | | -# version already on npm is skipped, so a retry converges. |
| 4 | +# sync-postgres-v0.4.0), and the destination packages — the ones with a CLI — |
| 5 | +# to GHCR as a container image after that. release-please calls this once per |
| 6 | +# package it released; re-run it by hand for an existing tag if a run failed — |
| 7 | +# a version already on npm is skipped and an image push is idempotent, so a |
| 8 | +# retry converges. |
7 | 9 |
|
8 | 10 | on: |
9 | 11 | workflow_call: |
|
35 | 37 | permissions: |
36 | 38 | contents: read |
37 | 39 | id-token: write |
| 40 | + outputs: |
| 41 | + component: ${{ steps.pkg.outputs.component }} |
| 42 | + destination: ${{ steps.pkg.outputs.destination }} |
| 43 | + version: ${{ steps.pkg.outputs.version }} |
| 44 | + description: ${{ steps.pkg.outputs.description }} |
| 45 | + image: ${{ steps.pkg.outputs.image }} |
38 | 46 | steps: |
39 | 47 | - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
40 | 48 | with: |
@@ -72,11 +80,20 @@ jobs: |
72 | 80 | *-*) NPM_TAG=beta ;; |
73 | 81 | *) NPM_TAG=latest ;; |
74 | 82 | esac |
| 83 | + # A package with a `bin` is a destination and ships as an image too; |
| 84 | + # the engine is a library and does not. The Dockerfile's DESTINATION |
| 85 | + # arg is the component without its sync- prefix. |
| 86 | + IMAGE="$(node -p "require('./$DIR/package.json').bin ? 'true' : 'false'")" |
| 87 | + DESCRIPTION="$(node -p "require('./$DIR/package.json').description ?? ''")" |
75 | 88 | { |
76 | 89 | echo "dir=$DIR" |
77 | 90 | echo "name=$NAME" |
| 91 | + echo "component=$COMPONENT" |
| 92 | + echo "destination=${COMPONENT#sync-}" |
78 | 93 | echo "version=$VERSION" |
79 | 94 | echo "npm_tag=$NPM_TAG" |
| 95 | + echo "image=$IMAGE" |
| 96 | + echo "description=$DESCRIPTION" |
80 | 97 | } >> "$GITHUB_OUTPUT" |
81 | 98 |
|
82 | 99 | # Socket Firewall is off until PUBLIC_SOCKET_FIREWALL_TOKEN reaches this |
@@ -119,3 +136,124 @@ jobs: |
119 | 136 | TARBALL="$(pnpm --filter "./$DIR" pack --json --pack-destination "$RUNNER_TEMP" \ |
120 | 137 | | node -p "JSON.parse(require('fs').readFileSync(0, 'utf8')).filename")" |
121 | 138 | npm publish "$TARBALL" --tag "$NPM_TAG" --access public --provenance |
| 139 | +
|
| 140 | + # A multi-arch image for each destination package, after its npm package is |
| 141 | + # out so the two never sit at different versions. The image name is the npm |
| 142 | + # name without its scope: @workos/sync-postgres → ghcr.io/workos/sync-postgres. |
| 143 | + publish-ghcr: |
| 144 | + name: Publish container image to GHCR |
| 145 | + needs: publish |
| 146 | + if: ${{ needs.publish.outputs.image == 'true' }} |
| 147 | + runs-on: ubuntu-latest |
| 148 | + permissions: |
| 149 | + contents: read |
| 150 | + packages: write |
| 151 | + steps: |
| 152 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 153 | + with: |
| 154 | + ref: ${{ inputs.tag_name }} |
| 155 | + persist-credentials: false |
| 156 | + |
| 157 | + - name: Determine image tags |
| 158 | + id: image |
| 159 | + env: |
| 160 | + COMPONENT: ${{ needs.publish.outputs.component }} |
| 161 | + VERSION: ${{ needs.publish.outputs.version }} |
| 162 | + OWNER: ${{ github.repository_owner }} |
| 163 | + run: | |
| 164 | + case "$VERSION" in |
| 165 | + *-*) CHANNEL=beta ;; |
| 166 | + *) CHANNEL=latest ;; |
| 167 | + esac |
| 168 | + # github.sha is the commit the workflow ran from, not the tag's. |
| 169 | + REVISION="$(git rev-parse HEAD)" |
| 170 | + SHORT_SHA="$(git rev-parse --short HEAD)" |
| 171 | + IMAGE="ghcr.io/${OWNER}/${COMPONENT}" |
| 172 | + { |
| 173 | + echo "tags=${IMAGE}:${VERSION},${IMAGE}:${CHANNEL},${IMAGE}:sha-${SHORT_SHA}" |
| 174 | + echo "revision=$REVISION" |
| 175 | + } >> "$GITHUB_OUTPUT" |
| 176 | +
|
| 177 | + - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 |
| 178 | + with: |
| 179 | + registry: ghcr.io |
| 180 | + username: ${{ github.actor }} |
| 181 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 182 | + |
| 183 | + # QEMU + Buildx let a single amd64 runner build and push a multi-arch |
| 184 | + # manifest list (amd64 + arm64) so ARM hosts pull a native image. The |
| 185 | + # node:24-alpine base is already multi-arch. |
| 186 | + - uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 |
| 187 | + - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 |
| 188 | + |
| 189 | + # Socket Firewall is off until PUBLIC_SOCKET_FIREWALL_TOKEN reaches this |
| 190 | + # repo. To turn it on, uncomment this block; the plain publish below is |
| 191 | + # then skipped, and a run without the firewall fails instead. |
| 192 | + # - name: Prepare Docker install config directory |
| 193 | + # run: mkdir -p "$RUNNER_TEMP/sfw-docker-npm" |
| 194 | + # |
| 195 | + # - name: Setup Socket Firewall |
| 196 | + # id: sfw |
| 197 | + # uses: workos/setup-socket-firewall@ca93dd8aa351f54f4729fe3377a9be23c631c25d |
| 198 | + # env: |
| 199 | + # NPM_CONFIG_USERCONFIG: ${{ runner.temp }}/sfw-docker-npm/.npmrc |
| 200 | + # with: |
| 201 | + # token: ${{ secrets.PUBLIC_SOCKET_FIREWALL_TOKEN }} |
| 202 | + # |
| 203 | + # - name: Require Socket Firewall for container publication |
| 204 | + # if: steps.sfw.outputs.active != 'true' |
| 205 | + # run: | |
| 206 | + # echo "::error::Socket Firewall must be active before container publication." |
| 207 | + # exit 1 |
| 208 | + # |
| 209 | + # - name: Publish image with Socket Firewall |
| 210 | + # uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 |
| 211 | + # with: |
| 212 | + # context: . |
| 213 | + # platforms: linux/amd64,linux/arm64 |
| 214 | + # push: true |
| 215 | + # tags: ${{ steps.image.outputs.tags }} |
| 216 | + # labels: | |
| 217 | + # org.opencontainers.image.version=${{ needs.publish.outputs.version }} |
| 218 | + # org.opencontainers.image.revision=${{ steps.image.outputs.revision }} |
| 219 | + # org.opencontainers.image.description=${{ needs.publish.outputs.description }} |
| 220 | + # build-args: | |
| 221 | + # DESTINATION=${{ needs.publish.outputs.destination }} |
| 222 | + # SFW_REQUIRED=true |
| 223 | + # add-hosts: | |
| 224 | + # registry.npmjs.org:127.0.0.1 |
| 225 | + # registry.yarnpkg.com:127.0.0.1 |
| 226 | + # secret-files: | |
| 227 | + # npmrc=${{ runner.temp }}/sfw-docker-npm/.npmrc |
| 228 | + # |
| 229 | + # - name: Teardown Socket Firewall |
| 230 | + # if: ${{ always() && steps.sfw.outputs.active == 'true' }} |
| 231 | + # uses: workos/setup-socket-firewall/teardown@ca93dd8aa351f54f4729fe3377a9be23c631c25d |
| 232 | + # |
| 233 | + # - name: Remove private Docker install config |
| 234 | + # if: ${{ always() }} |
| 235 | + # env: |
| 236 | + # SFW_NPM_CONFIG_FILE: ${{ runner.temp }}/sfw-docker-npm/.npmrc |
| 237 | + # run: | |
| 238 | + # rm -f "$SFW_NPM_CONFIG_FILE" |
| 239 | + # if [ -e "$SFW_NPM_CONFIG_FILE" ]; then |
| 240 | + # echo "::error::Private Docker install config was not removed." |
| 241 | + # exit 1 |
| 242 | + # fi |
| 243 | + |
| 244 | + # Once the Socket Firewall block is on, delete this step: the Require |
| 245 | + # step refuses to publish without the firewall, and the firewalled |
| 246 | + # publish takes its place. |
| 247 | + - name: Publish image |
| 248 | + uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 |
| 249 | + with: |
| 250 | + context: . |
| 251 | + platforms: linux/amd64,linux/arm64 |
| 252 | + push: true |
| 253 | + tags: ${{ steps.image.outputs.tags }} |
| 254 | + labels: | |
| 255 | + org.opencontainers.image.version=${{ needs.publish.outputs.version }} |
| 256 | + org.opencontainers.image.revision=${{ steps.image.outputs.revision }} |
| 257 | + org.opencontainers.image.description=${{ needs.publish.outputs.description }} |
| 258 | + build-args: | |
| 259 | + DESTINATION=${{ needs.publish.outputs.destination }} |
0 commit comments