From ba69ff3942f519e99e32a84af4cd67b3ee4a0f16 Mon Sep 17 00:00:00 2001 From: David Herman Date: Tue, 26 Mar 2024 21:39:16 -0700 Subject: [PATCH] First working draft of build automation for libraries! - README improveements * copy edits * coalesce directory layout docs into a table - build.yml takes ref instead of branch - setup action shares common setup routines - scripts contain a `"release"` script instead of `"tag"`, which simply dispatches release.yml --- pkgs/create-neon/data/templates/README.md.hbs | 84 +++------ .../data/templates/ci/github/.env.hbs | 1 + .../data/templates/ci/github/build.yml.hbs | 110 ++++++----- .../ci/github/manifest/scripts.json.hbs | 3 +- .../data/templates/ci/github/publish.yml.hbs | 176 ------------------ .../data/templates/ci/github/release.yml.hbs | 134 +++++++++++++ .../data/templates/ci/github/setup.yml.hbs | 78 ++++++++ .../data/templates/ci/github/test.yml.hbs | 23 +-- pkgs/create-neon/data/versions.json | 7 +- pkgs/create-neon/src/ci/github.ts | 5 +- 10 files changed, 316 insertions(+), 305 deletions(-) delete mode 100644 pkgs/create-neon/data/templates/ci/github/publish.yml.hbs create mode 100644 pkgs/create-neon/data/templates/ci/github/release.yml.hbs create mode 100644 pkgs/create-neon/data/templates/ci/github/setup.yml.hbs diff --git a/pkgs/create-neon/data/templates/README.md.hbs b/pkgs/create-neon/data/templates/README.md.hbs index 7fcff1cd5..31fd5555c 100644 --- a/pkgs/create-neon/data/templates/README.md.hbs +++ b/pkgs/create-neon/data/templates/README.md.hbs @@ -16,11 +16,11 @@ To run the build, run: $ npm run build ``` -This command uses the [@neon-rs/cli](https://github.com/neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`. +This command uses the [@neon-rs/cli](https://www.npmjs.com/package/@neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`. ## Exploring {{package.name}} -After building {{package.name}}, you can explore its exports at the Node REPL: +After building {{package.name}}, you can explore its exports at the Node console: ```sh $ npm run build @@ -34,12 +34,12 @@ $ node In the project directory, you can run: {{#unless packageSpec.library}} -### `npm install` +#### `npm install` Installs the project, including running `npm run build`. {{/unless}} -### `npm run build` +#### `npm run build` Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`. @@ -57,7 +57,7 @@ Similar to `npm run build` but generates a debug build with `cargo`. Similar to `npm run build` but uses [cross-rs](https://github.com/cross-rs/cross) to cross-compile for another platform. Use the [`CARGO_BUILD_TARGET`](https://doc.rust-lang.org/cargo/reference/config.html#buildtarget) environment variable to select the build target. -### `npm test` +#### `npm test` Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/). @@ -86,68 +86,32 @@ The directory structure of this project is: └── target/ ``` -### Cargo.toml - -The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. - -### README.md - -This file. - +| Entry | Purpose | +|----------------|------------------------------------------------------------------------------------------------------------------------------------------| +| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. | +| `README.md` | This file. | {{#if packageSpec}} -### lib/ - {{#eq packageSpec.library.lang compare="ts"}} -The directory containing the generated output from [tsc](https://typescriptlang.org). - -### ts/ - -The directory containing the TypeScript source files. - -### ts/index.mts - -Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax. - -### ts/index.cts - -Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid). - +| `lib` | The directory containing the generated output from [tsc](https://typescriptlang.org). | +| `ts` | The directory containing the TypeScript source files. | +| `ts/index.mts` | Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax. | +| `ts/index.cts` | Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid). | {{else}} -The directory containing the JavaScript source files. - +| `lib` | The directory containing The directory containing the JavaScript source files. | {{/eq}} -### platforms/ - -The directory containing distributions of the binary addon backend for each platform supported by this library. - +| `platforms` | The directory containing distributions of the binary addon backend for each platform supported by this library. | {{else}} -### index.node - -The binary module (aka Node addon) generated by building the project. This is the main module for this package, as dictated by the `"main"` key in `package.json`. - -Under the hood, a [Node addon](https://nodejs.org/api/addons.html) is a [dynamically-linked shared object](https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries). The `"build"` script produces this file by copying it from within the `target/` directory, which is where the Rust build produces the shared object. - +| `index.node` | The main module, a [Node addon](https://nodejs.org/api/addons.html) generated by the build and pointed to by `"main"` in `package.json`. | {{/if}} -### package.json - -The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. - -### src/ - -The directory tree containing the Rust source code for the project. - -### src/lib.rs - -The Rust library's main module. - -### target/ - -Binary artifacts generated by the Rust build. +| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. | +| `src` | The directory tree containing the Rust source code for the project. | +| `src/lib.rs` | The Rust library's main module. | +| `target` | Binary artifacts generated by the Rust build. | ## Learn More -To learn more about Neon, see the [Neon documentation](https://neon-bindings.com). - -To learn more about Rust, see the [Rust documentation](https://www.rust-lang.org). +Learn more about: -To learn more about Node, see the [Node documentation](https://nodejs.org). +- [Neon](https://neon-bindings.com). +- [Rust](https://www.rust-lang.org). +- [Node](https://nodejs.org). diff --git a/pkgs/create-neon/data/templates/ci/github/.env.hbs b/pkgs/create-neon/data/templates/ci/github/.env.hbs index 868db8f4b..0d2d2eb1b 100644 --- a/pkgs/create-neon/data/templates/ci/github/.env.hbs +++ b/pkgs/create-neon/data/templates/ci/github/.env.hbs @@ -1,4 +1,5 @@ NODE_VERSION=18.x NPM_REGISTRY=https://registry.npmjs.org +RUST_VERSION=stable ACTIONS_USER=github-actions ACTIONS_EMAIL=github-actions@github.com diff --git a/pkgs/create-neon/data/templates/ci/github/build.yml.hbs b/pkgs/create-neon/data/templates/ci/github/build.yml.hbs index b40b3e1da..2c752b696 100644 --- a/pkgs/create-neon/data/templates/ci/github/build.yml.hbs +++ b/pkgs/create-neon/data/templates/ci/github/build.yml.hbs @@ -3,11 +3,10 @@ name: Build on: workflow_call: inputs: - branch: - description: 'Branch to check out' - required: false + ref: + description: 'The branch, tag, or SHA to check out' + required: true type: string - default: {{#$}} github.event.repository.default_branch {{/$}} update-version: description: 'Update version before building?' required: false @@ -23,6 +22,11 @@ on: required: false type: boolean default: false + tag: + description: 'The release tag (ignored if github-release is false)' + required: false + type: string + default: '' jobs: matrix: @@ -34,33 +38,15 @@ jobs: - name: Checkout Code uses: actions/checkout@{{versions.actions.checkout}} with: - token: {{#$}} secrets.TAG_TOKEN || github.token {{/$}} - ref: {{#$}} inputs.branch {{/$}} - - name: Set Environment Variables - uses: falti/dotenv-action@{{versions.actions.dotenv}} - with: - path: ./.github/workflows/.env - export-variables: true - keys-case: bypass - - name: Install Node - uses: actions/setup-node@{{versions.actions.setupNode}} + ref: {{#$}} inputs.ref {{/$}} + - name: Setup Neon Environment + uses: ./.github/actions/setup with: - node-version: {{#$}} env.NODE_VERSION {{/$}} - registry-url: {{#$}} env.NPM_REGISTRY {{/$}} - cache: npm - - name: Install Dependencies - shell: bash - run: npm ci - - name: Install cargo-messages - shell: bash - run: npm ci - working-directory: ./pkgs/cargo-messages + use-rust: false - name: Look Up Matrix Data id: matrixData shell: bash - run: | - echo "json=$(node ../../dist/cli ci github | jq -rc)" >> "$GITHUB_OUTPUT" - working-directory: ./pkgs/cargo-messages + run: echo "json=$(npx neon ci github | jq -rc)" >> "$GITHUB_OUTPUT" - name: Compute Matrix id: matrix uses: actions/github-script@{{versions.actions.githubScript}} @@ -91,19 +77,15 @@ jobs: - name: Checkout Code uses: actions/checkout@{{versions.actions.checkout}} with: + ref: {{#$}} inputs.ref {{/$}} fetch-depth: 0 - - name: Set Environment Variables - uses: falti/dotenv-action@{{versions.actions.dotenv}} + - name: Setup Neon Environment + id: neon + uses: ./.github/actions/setup with: - path: ./.github/workflows/.env - export-variables: true - keys-case: bypass - - name: Diagnostics - shell: bash - run: git log -10 - - name: Install Dependencies - shell: bash - run: npm ci + use-cross: {{#$}} matrix.cfg.script == 'cross' {{/$}} + platform: {{#$}} matrix.cfg.platform {{/$}} + workspace: ./pkgs/cargo-messages - name: Update Version if: {{#$}} inputs.update-version {{/$}} shell: bash @@ -111,14 +93,48 @@ jobs: git config --global user.name $ACTIONS_USER git config --global user.email $ACTIONS_EMAIL npm version {{#$}} inputs.version {{/$}} -m "v%s" - - name: Check Versions - shell: bash - run: ./test/lint/check-versions.sh - name: Build - uses: neon-actions/build@{{versions.actions.neonBuild}} + 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 {{/$}} --pack-destination=./dist --json | jq -r '.[0].filename')) >> $GITHUB_OUTPUT + - name: Release + if: {{#$}} inputs.github-release {{/$}} + uses: softprops/action-gh-release@{{versions.actions.ghRelease}} with: - working-directory: ./pkgs/cargo-messages - node-version: {{#$}} env.NODE_VERSION {{/$}} - use-cross: {{#$}} !!matrix.cfg.cross {{/$}} - platform: {{#$}} matrix.cfg.platform {{/$}} - github-release: {{#$}} inputs.github-release {{/$}} + files: ./dist/{{#$}} steps.build.outputs.filename {{/$}} + tag_name: {{#$}} inputs.tag {{/$}} + + main: + name: Main + needs: [matrix] + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@{{versions.actions.checkout}} + with: + ref: {{#$}} inputs.ref {{/$}} + fetch-depth: 0 + - 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 --pack-destination=./dist)" >> $GITHUB_OUTPUT + - name: Release + if: {{#$}} inputs.github-release {{/$}} + uses: softprops/action-gh-release@{{versions.actions.ghRelease}} + with: + files: ./dist/{{#$}} steps.build.outputs.filename {{/$}} + tag_name: {{#$}} inputs.tag {{/$}} diff --git a/pkgs/create-neon/data/templates/ci/github/manifest/scripts.json.hbs b/pkgs/create-neon/data/templates/ci/github/manifest/scripts.json.hbs index 66eeb37ef..368ed351e 100644 --- a/pkgs/create-neon/data/templates/ci/github/manifest/scripts.json.hbs +++ b/pkgs/create-neon/data/templates/ci/github/manifest/scripts.json.hbs @@ -1,5 +1,4 @@ { - "tag": "npm version -m 'v%s'", - "posttag": "git push --follow-tags", + "release": "gh workflow run release.yml -f dryrun=false -f version=patch", "dryrun": "gh workflow run publish.yml -f dryrun=true" } diff --git a/pkgs/create-neon/data/templates/ci/github/publish.yml.hbs b/pkgs/create-neon/data/templates/ci/github/publish.yml.hbs deleted file mode 100644 index 96552073b..000000000 --- a/pkgs/create-neon/data/templates/ci/github/publish.yml.hbs +++ /dev/null @@ -1,176 +0,0 @@ -name: Publish - -run-name: | - {{#$}} (github.event_name == 'workflow_dispatch' && inputs.dryrun - && 'Dry run') - || (github.event_name == 'workflow_dispatch' - && format('Tag release: {0}', (inputs.version == 'custom' && inputs.custom) || inputs.version)) - || format('Publish: {0}', github.event.head_commit.message) {{/$}} - -on: - # Event: A maintainer has pushed a new release tag for publication. - push: - tags: - - v* - - # Event: A maintainer has used the GitHub Actions UI to initiate - # either tagging a new release for publication or doing a - # dry run. - 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 - default: 'patch' - 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 {{/$}} - tag: {{#$}} steps.tag.outputs.tag {{/$}} - publish: {{#$}} steps.publish.outputs.publish {{/$}} - 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: {{#$}} github.event_name == 'workflow_dispatch' && inputs.dryrun {{/$}} - shell: bash - run: echo dryrun=true >> "$GITHUB_OUTPUT" - - id: tag - name: Validate Tag Event - if: {{#$}} github.event_name == 'workflow_dispatch' && !inputs.dryrun {{/$}} - shell: bash - env: - TAG_TOKEN: {{#$}} secrets.TAG_TOKEN {{/$}} - run: | - if [[ -z $TAG_TOKEN ]]; then - echo "::error::Secret TAG_TOKEN is not defined for this GitHub repo." - echo "::error::To push a publish tag, this action requires:" - echo "::error:: • a GitHub Personal Access Token;" - echo "::error:: • with Read-Write access to this repo;" - echo "::error:: • stored as a repo secret named TAG_TOKEN." - echo "::error::See https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens for info about creating GitHub Personal Access Tokens." - 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 tag=true >> "$GITHUB_OUTPUT" - - id: publish - name: Validate Publish Event - if: {{#$}} github.event_name == 'push' {{/$}} - 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::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 >> "$GITHUB_OUTPUT" - - name: Checkout Code - uses: actions/checkout@{{versions.actions.checkout}} - with: - token: {{#$}} secrets.TAG_TOKEN || github.token {{/$}} - - name: Set Environment Variables - uses: falti/dotenv-action@{{versions.actions.dotenv}} - with: - path: ./.github/workflows/.env - export-variables: true - keys-case: bypass - - name: Install Node - uses: actions/setup-node@{{versions.actions.setupNode}} - with: - node-version: {{#$}} env.NODE_VERSION {{/$}} - registry-url: {{#$}} env.NPM_REGISTRY {{/$}} - cache: npm - - name: Install Dependencies - shell: bash - run: npm ci - - name: Tag Release (manual only) - if: {{#$}} steps.tag.outputs.tag {{/$}} - shell: bash - run: | - git config --global user.name $ACTIONS_USER - git config --global user.email $ACTIONS_EMAIL - npm run tag -- '{{#$}} (inputs.version == 'custom' && inputs.custom) || inputs.version {{/$}}' - - build: - name: Build - needs: [setup] - permissions: - contents: write - uses: ./.github/workflows/build.yml - with: - 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@{{versions.actions.checkout}} - with: - fetch-depth: 0 - - name: Set Environment Variables - uses: falti/dotenv-action@{{versions.actions.dotenv}} - with: - path: ./.github/workflows/.env - export-variables: true - keys-case: bypass - - name: Install Node - uses: actions/setup-node@{{versions.actions.setupNode}} - with: - node-version: {{#$}} env.NODE_VERSION {{/$}} - registry-url: {{#$}} env.NPM_REGISTRY {{/$}} - cache: npm - - name: Install Dependencies - shell: bash - run: npm ci - - name: Publish - uses: neon-actions/publish@{{versions.actions.neonPublish}} - env: - NODE_AUTH_TOKEN: {{#$}} secrets.NPM_TOKEN {{/$}} - with: - node-version: {{#$}} env.NODE_VERSION {{/$}} - registry-url: {{#$}} env.NPM_REGISTRY {{/$}} - fetch-binaries: "*.tgz" - github-release: true diff --git a/pkgs/create-neon/data/templates/ci/github/release.yml.hbs b/pkgs/create-neon/data/templates/ci/github/release.yml.hbs new file mode 100644 index 000000000..48fcdb1f1 --- /dev/null +++ b/pkgs/create-neon/data/templates/ci/github/release.yml.hbs @@ -0,0 +1,134 @@ +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 + default: 'patch' + 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 >> "$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::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 >> "$GITHUB_OUTPUT" + - name: Checkout Code + uses: actions/checkout@{{versions.actions.checkout}} + - name: Setup Neon Environment + uses: ./.github/actions/setup + with: + use-rust: false + - name: Tag Release (manual only) + if: {{#$}} !inputs.dryrun {{/$}} + 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) >> "$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@{{versions.actions.checkout}} + with: + fetch-depth: 0 + ref: {{#$}} needs.setup.outputs.ref {{/$}} + - name: Setup Neon Environment + uses: ./.github/actions/setup + with: + use-rust: false + - name: Fetch + uses: robinraju/release-downloader@{{versions.actions.releaseDownloader}} + 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 diff --git a/pkgs/create-neon/data/templates/ci/github/setup.yml.hbs b/pkgs/create-neon/data/templates/ci/github/setup.yml.hbs new file mode 100644 index 000000000..7e3dee085 --- /dev/null +++ b/pkgs/create-neon/data/templates/ci/github/setup.yml.hbs @@ -0,0 +1,78 @@ +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@{{versions.actions.dotenv}} + with: + path: ./.github/.env + export-variables: true + keys-case: bypass + - name: Install Node + uses: actions/setup-node@{{versions.actions.setupNode}} + 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 {{/$}}"]') >> $GITHUB_OUTPUT + working-directory: {{#$}} inputs.workspace {{/$}} + - name: Install Rust + if: {{#$}} inputs['use-rust'] == 'true' {{/$}} + uses: actions-rs/toolchain@{{versions.actions.setupRust}} + 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@{{versions.actions.cargoInstall}} + with: + crate: cross + - name: Node Version + id: node + shell: bash + run: | + # Trim the leading 'v' (e.g. "v18.19.0" ==> "18.19.0") + echo version=$(node --version | cut -c 2-) >> $GITHUB_OUTPUT + - name: Rust Version + if: {{#$}} inputs['use-rust'] == 'true' {{/$}} + id: rust + shell: bash + run: | + # Trim extraneous metadata (e.g. "rustc 1.70.0 (90c541806 2023-05-31)" ==> "1.70.0") + echo version=$(rustc --version | awk '{ print $2; }') >> $GITHUB_OUTPUT diff --git a/pkgs/create-neon/data/templates/ci/github/test.yml.hbs b/pkgs/create-neon/data/templates/ci/github/test.yml.hbs index b88f717a6..66090ac14 100644 --- a/pkgs/create-neon/data/templates/ci/github/test.yml.hbs +++ b/pkgs/create-neon/data/templates/ci/github/test.yml.hbs @@ -27,25 +27,16 @@ jobs: uses: actions/checkout@{{versions.actions.checkout}} with: fetch-depth: 0 - - name: Set Environment Variables - uses: falti/dotenv-action@{{versions.actions.dotenv}} + - name: Setup Neon Environment + id: neon + uses: ./.github/actions/setup with: - path: ./.github/workflows/.env - export-variables: true - keys-case: bypass - - name: Install Node - uses: actions/setup-node@{{versions.actions.setupNode}} - with: - node-version: {{#$}} env.NODE_VERSION {{/$}} - registry-url: {{#$}} env.NPM_REGISTRY {{/$}} - cache: npm - - name: Install Rust - uses: actions-rs/toolchain@{{versions.actions.setupRust}} - - name: Install Dependencies - shell: bash - run: npm ci --verbose + platform: linux-x64-gnu - name: Build shell: bash + env: + CARGO_BUILD_TARGET: {{#$}} steps.neon.outputs.target {{/$}} + NEON_BUILD_PLATFORM: linux-x64-gnu run: npm run debug - name: Test shell: bash diff --git a/pkgs/create-neon/data/versions.json b/pkgs/create-neon/data/versions.json index d8e2e998f..797dab112 100644 --- a/pkgs/create-neon/data/versions.json +++ b/pkgs/create-neon/data/versions.json @@ -1,6 +1,6 @@ { "neon": "1", - "neonCLI": "0.1.0", + "neonCLI": "0.1.64", "neonLoad": "0.1.0", "typescript": "5.3.3", "typesNode": "20.11.16", @@ -15,8 +15,11 @@ "githubScript": "v7", "setupNode": "v3", "setupRust": "v1", + "cargoInstall": "v2", "neonBuild": "v0.9", "neonPublish": "v0.4.1", - "dotenv": "v1" + "dotenv": "v1", + "ghRelease": "v1", + "releaseDownloader": "v1.7" } } diff --git a/pkgs/create-neon/src/ci/github.ts b/pkgs/create-neon/src/ci/github.ts index 4726aa0a3..8dd1beaa2 100644 --- a/pkgs/create-neon/src/ci/github.ts +++ b/pkgs/create-neon/src/ci/github.ts @@ -2,10 +2,11 @@ import { CI } from '../ci.js'; import path from 'node:path'; const TEMPLATES: Record = { - ".env.hbs": path.join(".github", "workflows", ".env"), + "setup.yml.hbs": path.join(".github", "actions", "setup", "action.yml"), + ".env.hbs": path.join(".github", ".env"), "build.yml.hbs": path.join(".github", "workflows", "build.yml"), "comments.yml.hbs": path.join(".github", "workflows", "comments.yml"), - "publish.yml.hbs": path.join(".github", "workflows", "publish.yml"), + "release.yml.hbs": path.join(".github", "workflows", "release.yml"), "test.yml.hbs": path.join(".github", "workflows", "test.yml") };