Skip to content

Commit a41958e

Browse files
authored
Merge pull request cycjimmy#225 from davidspek/feat/unset-gha
feat: add ability to unset GITHUB_ACTION env var
2 parents fbe9698 + 9e59817 commit a41958e

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ then make sure that you configure this in your `package.json` file:
5151
| extra_plugins | false | Extra plugins for pre-install. [[Details](#extra_plugins)] |
5252
| dry_run | false | Whether to run semantic release in `dry-run` mode. [[Details](#dry_run)] |
5353
| ci | false | Whether to run semantic release with CI support. [[Details](#ci)]<br>Support for **semantic-release above v16**. |
54+
| unset_gha_env | false | Whether to unset the GITHUB_ACTIONS environment variable. |
5455
| extends | false | Use a sharable configuration [[Details](#extends)] |
5556
| working_directory | false | Use another working directory for semantic release [[Details](#working_directory)] |
5657
| tag_format | false | Specify format of tag (useful for monorepos) |
@@ -264,6 +265,29 @@ steps:
264265
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
265266
```
266267

268+
#### unset_gha_env
269+
Setting this to true will unset the `GITHUB_ACTIONS` environment variable. This can be useful when wanting to validate things such as merging of a PR would create a valid release.
270+
271+
```yaml
272+
steps:
273+
- name: Checkout
274+
uses: actions/checkout@v4
275+
- name: Temporarily merge PR branch
276+
if: ${{ github.event_name == 'pull_request' }}
277+
run: |
278+
git config --global user.name github-actions
279+
git config --global user.email [email protected]
280+
git merge --no-ff origin/${{ github.event.pull_request.head.ref }} --message "${{ github.event.pull_request.title }}"
281+
- name: Semantic Release
282+
uses: cycjimmy/semantic-release-action@v4
283+
with:
284+
unset_gha_env: ${{ github.event_name == 'pull_request' }}
285+
ci: ${{ github.event_name == 'pull_request' && false || '' }}
286+
env:
287+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
288+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
289+
```
290+
267291
### Outputs
268292
| Output Parameter | Description |
269293
|:-------------------------:|-----------------------------------------------------------------------------------------------------------------------------------|

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ inputs:
2323
ci:
2424
required: false
2525
description: 'Whether to run semantic release with CI support (default: true). It will override the ci attribute in your configuration file'
26+
unset_gha_env:
27+
required: false
28+
description: 'Whether to unset the GITHUB_ACTIONS environment variable. This can be useful when trying to run semantic-release as part of PR checks.'
2629
extends:
2730
required: false
2831
description: 'One or several sharable configurations, https://semantic-release.gitbook.io/semantic-release/usage/configuration#extends'

src/handleOptions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ exports.handleRepositoryUrlOption = () => {
126126
core.debug(`repository_url input: ${repositoryUrl}`);
127127

128128
if (repositoryUrl) {
129-
return { r: repositoryUrl };
129+
return { r: repositoryUrl };
130130
} else {
131131
return {};
132132
}
133-
};
133+
};

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const release = async () => {
2727
await preInstall(core.getInput(inputs.extra_plugins));
2828
await preInstall(core.getInput(inputs.extends));
2929

30+
if (core.getInput(inputs.unset_gha_env) === 'true') {
31+
core.debug('Unset GITHUB_ACTIONS environment variable');
32+
delete process.env.GITHUB_ACTIONS;
33+
}
34+
3035
const semanticRelease = await import('semantic-release');
3136
const result = await semanticRelease.default({
3237
...handleBranchesOption(),

src/inputs.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"extra_plugins": "extra_plugins",
66
"dry_run": "dry_run",
77
"ci": "ci",
8+
"unset_gha_env": "unset_gha_env",
89
"extends": "extends",
910
"working_directory": "working_directory",
1011
"tag_format": "tag_format",

0 commit comments

Comments
 (0)