-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(release): separate poetry package vs regular release
- Loading branch information
1 parent
db80347
commit 3ac773e
Showing
5 changed files
with
244 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,117 @@ | ||
# GitHub Action Release | ||
|
||
## Description | ||
|
||
GitHub Action that publishes a new release. | ||
|
||
## Configuration | ||
|
||
### Step1: Set any [Semantic Release Configuration](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration) in your repository. | ||
|
||
### Step2: [Add Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) in your repository for the [Semantic Release Authentication](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/ci-configuration.md#authentication) Environment Variables. | ||
|
||
### Step3: Add a [Workflow File](https://help.github.com/en/articles/workflow-syntax-for-github-actions) to your repository to create custom automated processes. | ||
|
||
## Usage | ||
|
||
```yaml | ||
steps: | ||
- name: Release | ||
uses: open-turo/actions-python/release-poetry-package@v2 | ||
with: | ||
## example value for github-token provided below | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
``` | ||
**IMPORTANT**: `GITHUB_TOKEN` does not have the required permissions to operate on protected branches. | ||
If you are using this action for protected branches, replace `GITHUB_TOKEN` with [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). If using the `@semantic-release/git` plugin for protected branches, avoid persisting credentials as part of `actions/checkout@v3` by setting the parameter `persist-credentials: false`. This credential does not have the required permission to operate on protected branches. | ||
|
||
## Inputs | ||
|
||
| parameter | description | required | default | | ||
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------- | | ||
| checkout-repo | Perform checkout as first step of action | `false` | true | | ||
| dry-run | Whether to run semantic release in `dry-run` mode. It will override the `dryRun` attribute in your configuration file | `false` | `false` | | ||
| extra-plugins | Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config. | `false` | @open-turo/semantic-release-config@^1.4.0 | | ||
| github-token | GitHub token that can checkout the repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN' | `true` | | | ||
|
||
## Outputs | ||
|
||
| parameter | description | | ||
| ------------------------- | ----------------------------------- | | ||
| new-release-published | Whether a new release was published | | ||
| new-release-version | Version of the new release | | ||
| new-release-major-version | Major version of the new release | | ||
|
||
## Runs | ||
|
||
This action is an `composite` action. | ||
|
||
## Additional Examples | ||
|
||
### extra-plugins example | ||
|
||
The Action can be used with `extra-plugins` option to specify plugins which are not in the [default list of plugins of semantic release](https://semantic-release.gitbook.io/semantic-release/usage/plugins#default-plugins). When using this option, please make sure that these plugins are also mentioned in your [semantic release config's plugins](https://semantic-release.gitbook.io/semantic-release/usage/configuration#plugins) array. | ||
|
||
For example, if you want to use `@semantic-release/git` and `@semantic-release/changelog` extra plugins, these must be added to `extra-plugins` in your actions file and `plugins` in your [release config file](https://semantic-release.gitbook.io/semantic-release/usage/configuration#configuration-file) as shown bellow: | ||
|
||
Github Action Workflow: | ||
|
||
```yaml | ||
steps: | ||
- name: Release | ||
uses: open-turo/actions-python/release-poetry-package@v2 | ||
with: | ||
# You can specify specifying version range for the extra plugins if you prefer. | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
extra-plugins: | | ||
@semantic-release/[email protected] | ||
@semantic-release/git | ||
``` | ||
|
||
Similar to parameter `semantic_version`. _It is recommended to manually specify a version of semantic-release plugins to prevent errors caused._ | ||
|
||
Release Config: | ||
|
||
```diff | ||
plugins: [ | ||
. | ||
+ "@semantic-release/changelog" | ||
+ "@semantic-release/git", | ||
] | ||
``` | ||
|
||
### dry-run example | ||
|
||
```yaml | ||
jobs: | ||
build: | ||
steps: | ||
- name: Release | ||
uses: open-turo/actions-python/release-poetry-package@v2 | ||
with: | ||
dry-run: true | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
``` | ||
|
||
### using output parameters example | ||
|
||
```yaml | ||
jobs: | ||
build: | ||
steps: | ||
- name: Release | ||
uses: open-turo/actions-python/release-poetry-package@v2 | ||
id: semantic # Need an `id` for output variables | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Do something when a new release published | ||
if: steps.semantic.outputs.new-release-published == 'true' | ||
run: | | ||
echo ${{ steps.semantic.outputs.new-release-version }} | ||
echo ${{ steps.semantic.outputs.new-release-major-version }} | ||
``` | ||
## Notes | ||
- By default, this action will perform actions/checkout as its first step. |
This file contains 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,115 @@ | ||
name: Python Release & Publish | ||
description: Python that publishes a new release. | ||
inputs: | ||
checkout-repo: | ||
required: false | ||
description: Perform checkout as first step of action | ||
default: "true" | ||
github-token: | ||
required: true | ||
description: GitHub token that can checkout the repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN' | ||
default: ${{ github.token }} | ||
pypi-token: | ||
required: false | ||
description: PyPI token that can checkout the repository as well as create tags/releases against it. e.g. 'secrets.PYPI_TOKEN' | ||
dry-run: | ||
required: false | ||
description: Whether to run semantic release in `dry-run` mode. It will override the `dryRun` attribute in your configuration file | ||
default: "false" | ||
extra-plugins: | ||
required: false | ||
description: Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config. | ||
default: | | ||
@open-turo/semantic-release-config@^1.4.0 | ||
git-user-name: | ||
required: false | ||
description: User name to associate with release version bump commit. | ||
default: Github Actions | ||
git-user-email: | ||
required: false | ||
description: User email to associate with release version bump commit. | ||
default: [email protected] | ||
outputs: | ||
new-release-published: | ||
description: Whether a new release was published | ||
value: ${{ steps.release.outputs.new_release_published }} | ||
new-release-version: | ||
description: Version of the new release | ||
value: ${{ steps.release.outputs.new_release_version || steps.version.outputs.new_release_version }} | ||
new-release-major-version: | ||
description: Major version of the new release | ||
value: ${{ steps.release.outputs.new_release_major_version }} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
if: inputs.checkout-repo == 'true' | ||
with: | ||
fetch-depth: 0 | ||
persist-credentials: false | ||
- name: Authorize | ||
uses: open-turo/action-git-auth@v2 | ||
with: | ||
github-personal-access-token: ${{ inputs.github-token }} | ||
- name: Set node.js version | ||
if: hashFiles('.node-version') == '' | ||
shell: bash | ||
run: echo '16.14.2' > .node-version | ||
- name: Setup tools | ||
uses: actions/setup-python@v5 | ||
- name: Install poetry | ||
run: pip install poetry | ||
shell: bash | ||
- name: Version | ||
id: version | ||
uses: cycjimmy/semantic-release-action@v3 | ||
with: | ||
dry_run: true | ||
branches: | | ||
['${{ github.ref_name }}'] | ||
extra_plugins: ${{ inputs.extra-plugins }} | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github-token }} | ||
PYPI_TOKEN: ${{ inputs.pypi-token }} | ||
- name: Update package version (non-poetry) | ||
if: hashFiles('poetry.lock') == '' && steps.version.outputs.new_release_published != 'false' | ||
shell: bash | ||
run: echo "::warning::New version published for non-poetry package, version must be updated manually in setup.py and code." | ||
- name: Update package version (non-poetry) | ||
if: hashFiles('poetry.lock') != '' && steps.version.outputs.new_release_published != 'false' | ||
shell: bash | ||
run: | | ||
# Use poetry to bump the version in pyproject.toml | ||
poetry version "${{ steps.version.outputs.new_release_version }}" | ||
# Specify the user name and email which is required to commit with a token auth | ||
git config user.email "${{ inputs.git-user-name }}" | ||
git config user.name "${{ inputs.git-user-email }}" | ||
# Commit the bumped project version with a non-semver chore: commit message | ||
git add pyproject.toml | ||
git --no-pager diff --staged | ||
git commit --author="${{ inputs.git-user-name }} <${{ inputs.git-user-email }}>" -m "chore: release ${{ steps.version.outputs.new_release_version }}" -m "[skip actions]" | ||
# Push the changes to the current (should be main) branch, if this is not a dry-run | ||
# TODO: This might not be super safe, we should consider that this could | ||
# be broken with beta/alpha releases, and might need an explicit check | ||
# somehow to ensure we're not releasing poorly against a branch that | ||
# shouldn't do so | ||
if [[ "${{ inputs.dry-run }}" == "false" ]]; then | ||
git push || { echo "::error:: Failed to push version update for pyproject.toml, check your github-token permissions, or branch protections."; exit 1; } | ||
fi | ||
# Nice logging, generate success exit code from this run step | ||
echo "::notice::Version successfully updated in pyproject.toml to ${{ steps.version.outputs.new_release_version }}." | ||
- name: Release | ||
id: release | ||
if: steps.version.outputs.new_release_published == 'true' | ||
uses: cycjimmy/semantic-release-action@v3 | ||
with: | ||
dry_run: ${{ inputs.dry-run }} | ||
extra_plugins: ${{ inputs.extra-plugins }} | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github-token }} | ||
PYPI_TOKEN: ${{ inputs.pypi-token }} |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -9,9 +9,6 @@ inputs: | |
required: true | ||
description: GitHub token that can checkout the repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN' | ||
default: ${{ github.token }} | ||
pypi-token: | ||
required: false | ||
description: PyPI token that can checkout the repository as well as create tags/releases against it. e.g. 'secrets.PYPI_TOKEN' | ||
dry-run: | ||
required: false | ||
description: Whether to run semantic release in `dry-run` mode. It will override the `dryRun` attribute in your configuration file | ||
|
@@ -21,14 +18,6 @@ inputs: | |
description: Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config. | ||
default: | | ||
@open-turo/semantic-release-config@^1.4.0 | ||
git-user-name: | ||
required: false | ||
description: User name to associate with release version bump commit. | ||
default: Github Actions | ||
git-user-email: | ||
required: false | ||
description: User email to associate with release version bump commit. | ||
default: [email protected] | ||
outputs: | ||
new-release-published: | ||
description: Whether a new release was published | ||
|
@@ -47,69 +36,13 @@ runs: | |
if: inputs.checkout-repo == 'true' | ||
with: | ||
fetch-depth: 0 | ||
persist-credentials: false | ||
- name: Authorize | ||
uses: open-turo/action-git-auth@v2 | ||
with: | ||
github-personal-access-token: ${{ inputs.github-token }} | ||
- name: Set node.js version | ||
if: hashFiles('.node-version') == '' | ||
shell: bash | ||
run: echo '16.14.2' > .node-version | ||
- name: Setup tools | ||
uses: actions/setup-python@v5 | ||
- name: Install poetry | ||
run: pip install poetry | ||
shell: bash | ||
- name: Version | ||
id: version | ||
uses: cycjimmy/semantic-release-action@v3 | ||
with: | ||
dry_run: true | ||
branches: | | ||
['${{ github.ref_name }}'] | ||
extra_plugins: ${{ inputs.extra-plugins }} | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github-token }} | ||
PYPI_TOKEN: ${{ inputs.pypi-token }} | ||
- name: Update package version (non-poetry) | ||
if: hashFiles('poetry.lock') == '' && steps.version.outputs.new_release_published != 'false' | ||
shell: bash | ||
run: echo "::warning::New version published for non-poetry package, version must be updated manually in setup.py and code." | ||
- name: Update package version (non-poetry) | ||
if: hashFiles('poetry.lock') != '' && steps.version.outputs.new_release_published != 'false' | ||
shell: bash | ||
run: | | ||
# Use poetry to bump the version in pyproject.toml | ||
poetry version "${{ steps.version.outputs.new_release_version }}" | ||
# Specify the user name and email which is required to commit with a token auth | ||
git config user.email "${{ inputs.git-user-name }}" | ||
git config user.name "${{ inputs.git-user-email }}" | ||
# Commit the bumped project version with a non-semver chore: commit message | ||
git add pyproject.toml | ||
git --no-pager diff --staged | ||
git commit --author="${{ inputs.git-user-name }} <${{ inputs.git-user-email }}>" -m "chore: release ${{ steps.version.outputs.new_release_version }}" -m "[skip actions]" | ||
# Push the changes to the current (should be main) branch, if this is not a dry-run | ||
# TODO: This might not be super safe, we should consider that this could | ||
# be broken with beta/alpha releases, and might need an explicit check | ||
# somehow to ensure we're not releasing poorly against a branch that | ||
# shouldn't do so | ||
if [[ "${{ inputs.dry-run }}" == "false" ]]; then | ||
git push || { echo "::error:: Failed to push version update for pyproject.toml, check your github-token permissions, or branch protections."; exit 1; } | ||
fi | ||
# Nice logging, generate success exit code from this run step | ||
echo "::notice::Version successfully updated in pyproject.toml to ${{ steps.version.outputs.new_release_version }}." | ||
- name: Release | ||
- uses: open-turo/actions-release/semantic-release@v4 | ||
id: release | ||
if: steps.version.outputs.new_release_published == 'true' | ||
uses: cycjimmy/semantic-release-action@v3 | ||
with: | ||
dry_run: ${{ inputs.dry-run }} | ||
extra_plugins: ${{ inputs.extra-plugins }} | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github-token }} | ||
PYPI_TOKEN: ${{ inputs.pypi-token }} | ||
github-token: ${{ inputs.github-token }} | ||
dry-run: ${{ inputs.dry-run }} | ||
extra-plugins: ${{ inputs.extra-plugins }} |