-
Notifications
You must be signed in to change notification settings - Fork 1
feat: extract version action #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
44c12b0
feat: extract version action
ilbertt 591686c
chore: update wording
ilbertt 7bfccc0
fix: ignore semver prerelease or build labels
ilbertt 2b6a05d
style: formatting
ilbertt bee9555
refactor: support more projects
ilbertt 914f837
Merge remote-tracking branch 'origin/main' into luca/extract-version-…
ilbertt 2f26da8
refactor: use utils
ilbertt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| - `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 }}" | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.