Skip to content

Commit

Permalink
Multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
keichan34 committed Jan 10, 2025
1 parent 8dfcda5 commit b876589
Show file tree
Hide file tree
Showing 26 changed files with 589 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .github/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NODE_VERSION=22.x
NPM_REGISTRY=https://registry.npmjs.org
RUST_VERSION=stable
ACTIONS_USER=github-actions
ACTIONS_EMAIL=[email protected]
76 changes: 76 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: 'Setup Neon'
description: 'Setup the Neon toolchain.'
inputs:
platform:
description: 'Platform being built for.'
required: false
default: ''
use-rust:
description: 'Install Rust?'
required: false
default: 'true'
use-cross:
description: 'Install cross-rs?'
required: false
default: 'false'
workspace:
description: 'Path to workspace being setup.'
required: false
default: '.'
outputs:
rust:
description: 'Rust version installed.'
value: ${{ steps.rust.outputs.version }}
node:
description: 'Node version installed.'
value: ${{ steps.node.outputs.version }}
target:
description: 'Rust target architecture installed.'
value: ${{ steps.target.outputs.target }}
runs:
using: "composite"
steps:
- name: Set Environment Variables
uses: falti/dotenv-action@d1cd55661714e830a6e26f608f81d36e23424fed # v1.1.2
with:
path: ./.github/.env
export-variables: true
keys-case: bypass
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: ${{ env.NPM_REGISTRY }}
cache: npm
- name: Install Dependencies
shell: bash
run: npm ci
- name: Compute Rust Target
if: ${{ inputs['use-rust'] == 'true' }}
id: target
shell: bash
run: echo target=$(npx neon list-platforms | jq -r '.["${{ inputs.platform }}"]') | tee -a $GITHUB_OUTPUT
working-directory: ${{ inputs.workspace }}
- name: Install Rust
if: ${{ inputs['use-rust'] == 'true' }}
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
target: ${{ steps.target.outputs.target }}
override: true
- name: Install cross-rs
if: ${{ inputs['use-cross'] == 'true' }}
uses: baptiste0928/cargo-install@v3
with:
crate: cross
- name: Node Version
id: node
shell: bash
run: |
echo version=$(node -e 'console.log(process.versions.node)') | tee -a $GITHUB_OUTPUT
- name: Rust Version
if: ${{ inputs['use-rust'] == 'true' }}
id: rust
shell: bash
run: |
echo version=$(cargo -Vv | fgrep release: | cut -d' ' -f2) | tee -a $GITHUB_OUTPUT
137 changes: 137 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Build

on:
workflow_call:
inputs:
ref:
description: 'The branch, tag, or SHA to check out'
required: true
type: string
update-version:
description: 'Update version before building?'
required: false
type: boolean
default: false
version:
description: 'Version update (ignored if update-version is false)'
required: false
type: string
default: 'patch'
github-release:
description: 'Publish GitHub release?'
required: false
type: boolean
default: false
tag:
description: 'The release tag (ignored if github-release is false)'
required: false
type: string
default: ''

jobs:
matrix:
name: Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.result }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Neon Environment
uses: ./.github/actions/setup
with:
use-rust: false
- name: Look Up Matrix Data
id: matrixData
shell: bash
run: echo "json=$(npx neon show ci github | jq -rc)" | tee -a $GITHUB_OUTPUT
- name: Compute Matrix
id: matrix
uses: actions/github-script@v7
with:
script: |
const platforms = ${{ steps.matrixData.outputs.json }};
const macOS = platforms.macOS.map(platform => {
return { os: "macos-latest", platform, script: "build" };
});
const windows = platforms.Windows.map(platform => {
return { os: "windows-latest", platform, script: "build" };
});
const linux = platforms.Linux.map(platform => {
return { os: "ubuntu-latest", platform, script: "cross" };
});
return [...macOS, ...windows, ...linux];
binaries:
name: Binaries
needs: [matrix]
strategy:
matrix:
cfg: ${{ fromJSON(needs.matrix.outputs.matrix) }}
runs-on: ${{ matrix.cfg.os }}
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Neon Environment
id: neon
uses: ./.github/actions/setup
with:
use-cross: ${{ matrix.cfg.script == 'cross' }}
platform: ${{ matrix.cfg.platform }}
- name: Update Version
if: ${{ inputs.update-version }}
shell: bash
run: |
git config --global user.name $ACTIONS_USER
git config --global user.email $ACTIONS_EMAIL
npm version ${{ inputs.version }} -m "v%s"
- name: Build
shell: bash
env:
CARGO_BUILD_TARGET: ${{ steps.neon.outputs.target }}
NEON_BUILD_PLATFORM: ${{ matrix.cfg.platform }}
run: npm run ${{ matrix.cfg.script }}
- name: Pack
id: pack
shell: bash
run: |
mkdir -p dist
echo filename=$(basename $(npm pack ./platforms/${{ matrix.cfg.platform }} --silent --pack-destination=./dist --json | jq -r '.[0].filename')) | tee -a $GITHUB_OUTPUT
- name: Release
if: ${{ inputs.github-release }}
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4
with:
files: ./dist/${{ steps.pack.outputs.filename }}
tag_name: ${{ inputs.tag }}

main:
name: Main
needs: [matrix]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Neon Environment
uses: ./.github/actions/setup
with:
use-rust: false
- name: Pack
id: pack
shell: bash
run: |
mkdir -p dist
echo "filename=$(npm pack --silent --pack-destination=./dist)" | tee -a $GITHUB_OUTPUT
- name: Release
if: ${{ inputs.github-release }}
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4
with:
files: ./dist/${{ steps.pack.outputs.filename }}
tag_name: ${{ inputs.tag }}
33 changes: 0 additions & 33 deletions .github/workflows/cicd.yml

This file was deleted.

135 changes: 135 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Release

run-name: |
${{ (inputs.dryrun && 'Dry run')
|| format('Release: {0}', (inputs.version == 'custom' && inputs.custom) || inputs.version) }}
on:
workflow_dispatch:
inputs:
dryrun:
description: 'Dry run (no npm publish)'
required: false
type: boolean
default: true
version:
description: 'Version component to update (or "custom" to provide exact version)'
required: true
type: choice
options:
- patch
- minor
- major
- prepatch
- preminor
- premajor
- prerelease
- custom
custom:
description: 'Custom version'
required: false
default: ''

jobs:
setup:
name: Setup
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
dryrun: ${{ steps.dryrun.outputs.dryrun }}
publish: ${{ steps.publish.outputs.publish }}
ref: ${{ steps.tag.outputs.tag || github.event.repository.default_branch }}
tag: ${{ steps.tag.outputs.tag || '' }}
steps:
- name: Validate Workflow Inputs
if: ${{ inputs.version == 'custom' && inputs.custom == '' }}
shell: bash
run: |
echo '::error::No custom version number provided'
exit 1
- id: dryrun
name: Validate Dry Run Event
if: ${{ inputs.dryrun }}
shell: bash
run: echo dryrun=true | tee -a $GITHUB_OUTPUT
- id: publish
name: Validate Publish Event
if: ${{ !inputs.dryrun }}
shell: bash
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [[ -z $NPM_TOKEN ]]; then
echo "::error::Secret NPM_TOKEN is not defined for this GitHub repo."
echo "::error::To publish to npm, this action requires:"
echo "::error:: • an npm access token;"
echo "::error:: • with Read-Write access to this project's npm packages;"
echo "::error:: • stored as a repo secret named NPM_TOKEN."
echo "::error::See https://docs.npmjs.com/about-access-tokens for info about creating npm tokens."
echo "::error:: 💡 The simplest method is to create a Classic npm token of type Automation."
echo "::error:: 💡 For greater security, consider using a Granual access token."
echo "::error::See https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions for info about how to store GitHub repo secrets."
exit 1
fi
echo publish=true | tee -a $GITHUB_OUTPUT
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Neon Environment
uses: ./.github/actions/setup
with:
use-rust: false
- name: Tag Release
if: ${{ !inputs.dryrun }}
id: tag
shell: bash
run: |
git config --global user.name $ACTIONS_USER
git config --global user.email $ACTIONS_EMAIL
npm version -m 'v%s' '${{ (inputs.version == 'custom' && inputs.custom) || inputs.version }}'
git push --follow-tags
echo tag=$(git describe --abbrev=0) | tee -a $GITHUB_OUTPUT
build:
name: Build
needs: [setup]
permissions:
contents: write
uses: ./.github/workflows/build.yml
with:
ref: ${{ needs.setup.outputs.ref }}
tag: ${{ needs.setup.outputs.tag }}
update-version: ${{ !!needs.setup.outputs.dryrun }}
version: ${{ (inputs.version == 'custom' && inputs.custom) || inputs.version }}
github-release: ${{ !!needs.setup.outputs.publish }}

publish:
name: Publish
if: ${{ needs.setup.outputs.publish }}
needs: [setup, build]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ needs.setup.outputs.ref }}
- name: Setup Neon Environment
uses: ./.github/actions/setup
with:
use-rust: false
- name: Fetch
uses: robinraju/release-downloader@c39a3b234af58f0cf85888573d361fb6fa281534 # v1.10
with:
tag: ${{ needs.setup.outputs.tag }}
fileName: "*.tgz"
out-file-path: ./dist
- name: Publish
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
for p in ./dist/*.tgz ; do
npm publish --access public $p
done
Loading

0 comments on commit b876589

Please sign in to comment.