Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions actions/extract-version/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Extract version action

This action extracts semantic version parts using the Commitizen CLI, or directly from a supported file if provided.

Supported files when `file` is provided:

- `package.json` (`version`)
- `Cargo.toml` (`version = "x.y.z"`)

If `file` is omitted, the action runs `cz version -p` to obtain the version. This requires `cz` to be installed and available in `PATH`.

## Action inputs

| Input | Description | Default |
| ------ | -------------------------------------------------------------------------------- | ------- |
| `file` | Optional path to a file to parse. Supported files: `package.json`, `Cargo.toml`. | `''` |

## Action outputs
Comment thread
ilbertt marked this conversation as resolved.

- `major`: The major version (e.g., `1`).
- `minor`: The minor version (e.g., `2`).
- `patch`: The patch version (e.g., `3`).
- `prerelease`: Everything after the patch (may include pre-release and/or build), e.g., `-beta.1`, `+build.5`, or `-rc.1+build.sha`.

## Example usage

```yaml
name: Extract version

on:
push:
branches:
- main

jobs:
extract:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Extract version from package.json
id: ver
uses: dfinity/ci-tools/actions/extract-version@main
with:
file: package.json

- name: Print
run: |
echo "major=${{ steps.ver.outputs.major }}"
echo "minor=${{ steps.ver.outputs.minor }}"
echo "patch=${{ steps.ver.outputs.patch }}"
echo "prerelease=${{ steps.ver.outputs.prerelease }}"

# Or, if there's a Commitizen config file in the repo:
- name: Extract version using Commitizen (cz)
id: ver_cz
uses: dfinity/ci-tools/actions/extract-version@main

- name: Print (cz)
run: |
echo "major=${{ steps.ver_cz.outputs.major }}"
echo "minor=${{ steps.ver_cz.outputs.minor }}"
echo "patch=${{ steps.ver_cz.outputs.patch }}"
echo "prerelease=${{ steps.ver_cz.outputs.prerelease }}"
```
21 changes: 21 additions & 0 deletions actions/extract-version/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Extract version
description: 'Extract semantic version parts using the Commitizen (cz) CLI or by parsing a supported file.'

inputs:
file:
description: 'Optional path to a file to parse. Supported files: package.json, Cargo.toml.'
required: false

outputs:
major:
description: 'The major version.'
minor:
description: 'The minor version.'
patch:
description: 'The patch version.'
prerelease:
description: 'Everything after the patch (pre-release and/or build metadata).'

runs:
using: node20
main: dist/index.js
10 changes: 10 additions & 0 deletions actions/extract-version/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as esbuild from 'esbuild';
import path from 'node:path';

await esbuild.build({
entryPoints: [path.resolve(import.meta.dirname, 'src', 'index.ts')],
outfile: path.resolve(import.meta.dirname, 'dist', 'index.js'),
bundle: true,
platform: 'node',
target: 'node20',
});
Loading