Skip to content

Commit

Permalink
chore: fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianolxp committed Dec 17, 2023
2 parents f82480e + da3ccef commit 326c676
Show file tree
Hide file tree
Showing 1,069 changed files with 138,945 additions and 123,720 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/pull_request_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ jobs:
with:
node-version: 20

- uses: lemonenergy/release-action@main
- uses: lemonenergy/release-action@develop
id: release-commit
with:
base-branch: main
github-token: ${{secrets.GITHUB_TOKEN}}

- uses: actions/github-script@v6
with:
script: |
if(!"${{steps.release-commit.outputs.version}}") return
github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
title: "v${{steps.release-commit.outputs.version}}"
})
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ Bumps package version and creates release.

## Inputs

| Name | Description | Required | Default |
| -------------- | ------------------------------------------------------------- | -------- | ------- |
| base-branch | Branch in which release will be merged | true | main |
| head-branch | Branch to be released | true | develop |
| github-token | Github token with access to commit in head-branch | true | |
| initial-branch | Initial version used if base-branch doesn't have package.json | false | 0.0.0 |
| Name | Description | Required | Default |
| --------------- | ------------------------------------------------------------- | -------- | ------- |
| base-branch | Branch in which release will be merged | true | main |
| head-branch | Branch to be released | true | develop |
| github-token | Github token with access to commit in head-branch | true | |
| initial-version | Initial version used if base-branch doesn't have package.json | false | 0.0.0 |

## Output

| Name | Description |
| ------- | ---------------- |
| version | the next version |

## Usage

Expand All @@ -18,3 +24,25 @@ Bumps package version and creates release.
with:
github-token: ${{secrets.PERSONAL_GITHUB_TOKEN}}
```
## Update PR title
In order to update the PR title with the release version for easier identification, add an `id` field to the release action and the following script:

```yml
- uses: lemonenergy/release-action@develop
id: release-commit
with:
github-token: ${{secrets.GITHUB_TOKEN}}
- uses: actions/github-script@v6
with:
script: |
if(!"${{steps.release-commit.outputs.version}}") return
github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
title: "v${{steps.release-commit.outputs.version}}"
})
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
description: 'Path where the target package.json is located'
default: ''

outputs:
version:
description: 'The next version'

runs:
using: 'node20'
main: 'index.js'
26 changes: 23 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ const checkEvent = (base, head) => {
const { eventName, payload } = github.context
const { pull_request } = payload

if (eventName !== EVENT) throw Error(`Event ${eventName} not supported. It should be ${EVENT}`)
if (eventName !== EVENT)
throw Error(`Event ${eventName} not supported. It should be ${EVENT}`)
const prBase = pull_request?.base?.ref
const prHead = pull_request?.head?.ref

if ( prBase === base && prHead === head) return
if (prBase === base && prHead === head) return

throw Error(`base_branch "${prBase}" and head_branch "${prHead}" provided doesn't match with the pull request base "${base}" and head "${head}"!`)
throw Error(
`base_branch "${prBase}" and head_branch "${prHead}" provided doesn't match with the pull request base "${base}" and head "${head}"!`,
)
}

const getLastVersion = async (base, initial = '0.0.0', targetPath = '') => {
Expand Down Expand Up @@ -128,6 +131,8 @@ const bump = async (lastVersion, release, targetPath = '') => {

const configGit = async head => {
await exec(`git fetch ${remote} ${head}:${head}`)
await exec(`git config --local user.email "action@github.com"`)
await exec(`git config --local user.name "Version Bump Action"`)
await exec(`git checkout ${head}`)
}

Expand All @@ -136,6 +141,18 @@ const pushBumpedVersionAndTag = async head => {
await exec(`git push -f --tags`)
}

const updatePRTitleWithNextVersion = async version => {
const { context } = github
const { payload } = context
const pull_number = payload.number

return octokit.pulls.update({
...context.repo,
pull_number,
title: `v${version}`,
})
}

const run = async () => {
const base = core.getInput('base-branch')
const head = core.getInput('head-branch')
Expand All @@ -160,6 +177,9 @@ const run = async () => {
console.log(`bumped to version ${version}!`)
await pushBumpedVersionAndTag(head)
console.log(`version ${version} pushed!`)
await updatePRTitleWithNextVersion(version)
console.log(`PR title updated with v${version}`)
core.setOutput('version', version)
} catch (e) {
core.setFailed(e)
}
Expand Down
Loading

0 comments on commit 326c676

Please sign in to comment.