Skip to content
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

feat: added a JSON file output upon completing the changeset #171

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: added a JSON file output upon completing the changeset
  • Loading branch information
Mees van Dongen committed Mar 4, 2024
commit e30d9b0018df19fd714d8980ef61a7a29a49ef34
5 changes: 5 additions & 0 deletions .changeset/big-taxis-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'changesets-gitlab': minor
---

Added a JSON file output upon completing the changeset. This file can be used to inform future steps in the pipeline of the published packages.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ GitLab CI cli for [changesets](https://github.com/atlassian/changesets) like its
- `INPUT_TARGET_BRANCH` -> The merge request target branch. Defaults to current branch
- `INPUT_CREATE_GITLAB_RELEASES` - A boolean value to indicate whether to create Gitlab releases after publish or not. Default true.

### Outputs
### Output

- `PUBLISHED` - A boolean value to indicate whether a publishing is happened or not
- `PUBLISHED_PACKAGES` - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]`
When publishing, a list of published packages is written to a file named `changesets-gitlab.output.json`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output location should be mentioned and would be better to be configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make it configurable. Another idea I had is to make the it configurable to have the output file at all, and default it to false. What do you think about that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, opt-in configurable.


```json
[
{ "name": "@xx/xx", "version": "1.2.0" },
{ "name": "@xx/xy", "version": "0.8.9" }
]
```

The existence of this file implies that a publish has happened. This file should be added to `.gitignore`.

### Environment Variables

Expand All @@ -51,7 +59,7 @@ GITLAB_TOKEN # required, token with accessibility to push
GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token
GITLAB_CI_USER_NAME # optional, username with accessibility to push, used in pairs of the above token (if it was personal access token). If not set read it from the Gitlab API
GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com`
GITLAB_COMMENT_TYPE # optional, type of the comment. defaults to `discussion`. can be set to `note` to not create a discussion instead of a thread
GITLAB_COMMENT_TYPE # optional, type of the comment. defaults to `discussion` (thread that needs to be resolved). can be set to `note` to create a comment instead.
GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI
DEBUG_GITLAB_CREDENTIAL # optional, default `false`
```
Expand Down
14 changes: 6 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { URL } from 'node:url'

import { getInput, setFailed, setOutput, exportVariable } from '@actions/core'
import { getInput, setFailed } from '@actions/core'
import { exec } from '@actions/exec'
import fs from 'fs-extra'

Expand All @@ -26,9 +26,6 @@ export const main = async ({
DEBUG_GITLAB_CREDENTIAL = 'false',
} = env

setOutput('published', false)
setOutput('publishedPackages', [])

if (CI) {
console.log('setting git user')
await setupUser()
Expand Down Expand Up @@ -91,10 +88,11 @@ export const main = async ({
})

if (result.published) {
setOutput('published', true)
setOutput('publishedPackages', result.publishedPackages)
exportVariable('PUBLISHED', true)
exportVariable('PUBLISHED_PACKAGES', result.publishedPackages)
fs.writeJsonSync(
'./changesets-gitlab.output.json',
JounQin marked this conversation as resolved.
Show resolved Hide resolved
result.publishedPackages,
)

if (published) {
execSync(published)
}
Expand Down