Skip to content

Commit

Permalink
Cargo dist
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Jan 22, 2025
1 parent 82c0da8 commit 4514a8d
Show file tree
Hide file tree
Showing 10 changed files with 543 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

on:
pull_request:
# pull_request is not needed because cargo-dist's plan steps will run on pull_request and that calls ci.yml
workflow_call:
workflow_dispatch:
push:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build release Docker image

on:
workflow_call:
inputs:
# comes from cargo-dist workflow call
plan:
required: true
type: string

env:
PLAN: ${{ inputs.plan }}

jobs:
build-docker-image:
name: Build release Docker image
needs: [run-tests]
uses: ./.github/workflows/docker.yml
secrets: inherit
with:
pushToDockerHub: true
parca: true
23 changes: 12 additions & 11 deletions .github/workflows/helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ name: Release helm chart
on:
workflow_call:
inputs:
ref:
description: 'ref to build eg v0.8.0'
required: false
type: string
version:
description: 'push helm chart with this version, eg v0.8.0'
# comes from cargo-dist workflow call
plan:
required: true
type: string
workflow_dispatch:
inputs:
ref:
description: 'ref to build eg v0.8.0'
description: "ref to build eg v0.8.0"
required: false
type: string
version:
description: 'push helm chart with this version, eg v0.8.0'
description: "push helm chart with this version, eg 0.8.0"
required: true
type: string

env:
PLAN: ${{ inputs.plan }}

jobs:
release-helm-chart:
runs-on: ubuntu-latest
Expand All @@ -31,9 +32,9 @@ jobs:
- name: Write release version
id: version
run: |
VERSION=${{ inputs.version }}
echo Version: ${VERSION#v}
echo "VERSION=${VERSION#v}" >> "$GITHUB_OUTPUT"
VERSION="${{ inputs.version || "$(echo "$PLAN" | jq -r '[.releases[] | select(.app_name == "restate-server")][0].app_version')" }}"
echo Version: ${VERSION}
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Check helm versions
run: |
grep -qF 'version: "${{ steps.version.outputs.VERSION }}"' charts/restate-helm/Chart.yaml
Expand Down
121 changes: 65 additions & 56 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ name: Publish npm binary packages
on:
workflow_call:
inputs:
version:
description: 'version to label npm packages'
# comes from cargo-dist workflow call
plan:
required: true
type: string

env:
PLAN: ${{ inputs.plan }}

jobs:
publish-npm-binaries:
permissions:
Expand All @@ -16,6 +19,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
app_name:
- restate-cli
- restate-server
build:
- target: aarch64-apple-darwin
node_arch: arm64
Expand All @@ -29,98 +35,101 @@ jobs:
- target: aarch64-unknown-linux-musl
node_arch: arm64
node_os: linux

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "18.x"
registry-url: 'https://registry.npmjs.org'
registry-url: "https://registry.npmjs.org"

- name: Download binary build from in-progress workflow
- name: "Download GitHub Artifacts"
uses: actions/download-artifact@v4
with:
name: restate.${{ matrix.build.target }}.tar.gz
pattern: artifacts-*
merge-multiple: true

- name: Extract binaries
run: tar -xvzf restate.${{ matrix.build.target }}.tar.gz
run: tar -xvzf ${{ matrix.package.artifact }}-${{ matrix.build.target }}.tar.xz

- name: Publish to NPM
shell: bash
run: |
bin="$(echo "$PLAN" | jq -r '.artifacts["${{ matrix.package.artifact }}-${{ matrix.build.target }}.tar.xz"].assets[] | select(.kind == "executable").name')
cd npm
for bin in restate restate-server
do
export node_os="${{ matrix.build.node_os }}"
export node_os
node_arch="${{ matrix.build.node_arch }}"
export node_arch
# set the version
node_version="${{ inputs.version }}"
node_version="${node_version#v}"
export node_version
# set the package name
export node_pkg="${bin}-${node_os}-${node_arch}"
if npm view "@restatedev/${node_pkg}@${node_version}"
then
continue
fi
# create the package directory
mkdir -p "${node_pkg}/bin"
# generate package.json from the template
envsubst < package.json.tmpl > "${node_pkg}/package.json"
# copy the binary into the package
cp "../${bin}" "${node_pkg}/bin"
cp ../NOTICE "${node_pkg}"
cp ../LICENSE "${node_pkg}"
cp ../README.md "${node_pkg}"
# publish the package
pushd "${node_pkg}"
npm publish --access public
popd
done
node_os="${{ matrix.build.node_os }}"
export node_os
node_arch="${{ matrix.build.node_arch }}"
export node_arch
# set the version
node_version=$(echo "$PLAN" | jq -r '.releases[] | select(.app_name == "${{ matrix.app_name }}").app_version')"
export node_version
# set the package name
export node_pkg="${bin}-${node_os}-${node_arch}"
if npm view "@restatedev/${node_pkg}@${node_version}"
then
continue
fi
# create the package directory
mkdir -p "${node_pkg}/bin"
# generate package.json from the template
envsubst < package.json.tmpl > "${node_pkg}/package.json"
# copy the binary into the package
cp "../${bin}" "${node_pkg}/bin"
cp ../NOTICE "${node_pkg}"
cp ../LICENSE "${node_pkg}"
cp ../README.md "${node_pkg}"
# publish the package
pushd "${node_pkg}"
npm publish --access public
popd
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-npm-base:
needs: publish-npm-binaries
runs-on: ubuntu-latest
strategy:
matrix:
app_name:
- restate-cli
- restate-server
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "18.x"
registry-url: 'https://registry.npmjs.org'
registry-url: "https://registry.npmjs.org"

- name: Publish to npm
shell: bash
run: |
node_version="${{ inputs.version }}"
node_version="${node_version#v}"
node_version=$(echo "$PLAN" | jq -r '.releases[] | select(.app_name == "${{ matrix.app_name }}").app_version')"
bin="$(echo "$PLAN" | jq -r '.artifacts["${{ matrix.package.artifact }}-${{ matrix.build.target }}.tar.xz"].assets[] | select(.kind == "executable").name')
cd npm
for bin in restate restate-server
if npm view "@restatedev/${bin}@${node_version}"
then
continue
fi
pushd "${bin}"
sed -i "s/\"version\": \".*\",/\"version\": \"${node_version}\",/" package.json
for os in linux darwin
do
if npm view "@restatedev/${bin}@${node_version}"
then
continue
fi
pushd "${bin}"
sed -i "s/\"version\": \".*\",/\"version\": \"${node_version}\",/" package.json
for os in linux darwin
for arch in x64 arm64
do
for arch in x64 arm64
do
sed -i "s|\"@restatedev/${bin}-${os}-${arch}\": \".*\"|\"@restatedev/${bin}-${os}-${arch}\": \"${node_version}\"|" package.json
done
sed -i "s|\"@restatedev/${bin}-${os}-${arch}\": \".*\"|\"@restatedev/${bin}-${os}-${arch}\": \"${node_version}\"|" package.json
done
curl https://raw.githubusercontent.com/restatedev/restate/main/README.md -o README.md
npm install
npm run build
npm publish --access public
popd
done
curl https://raw.githubusercontent.com/restatedev/restate/main/README.md -o README.md
npm install
npm run build
npm publish --access public
popd
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading

0 comments on commit 4514a8d

Please sign in to comment.