Skip to content

Commit

Permalink
Add config file support and dry run option
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed May 30, 2024
1 parent c183726 commit bee1f30
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .github/release-notes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
changelog:
exclude:
labels:
- skip-changelog
categories:
- title: Changelog
labels:
- release-notes
39 changes: 39 additions & 0 deletions .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:

Expand Down Expand Up @@ -39,3 +42,39 @@ jobs:
echo "Release URL: ${{ steps.draft-release.outputs.release-url }}"
echo "Release ID: ${{ steps.draft-release.outputs.release-id }}"
echo "Release Sections: ${{ steps.draft-release.outputs.release-sections }}"
test-dry-run-config:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./
id: draft-release
with:
config-path: .github/release-notes.yml
dry-run: true
variables: |
helm-chart=v0.1.1
foo=bar
my-variable=My Variable
notes-header: |
## Welcome to the {{version}} release of Draft Release
The previous release was {{previous-version}}.
This is some text to welcome you to the release {{version-number}}.
## Helm Chart
The Helm Chart version for this release is {{helm-chart}}.
## My Variable
The value of my variable is {{my-variable}}.
notes-footer: |
## Upgrade
- For Docker, use the {{version}} image from Docker Hub.
- For Binaries use the {{version-number}} release from GitHub.
- For Helm Chart, use the {{helm-chart}} version.
- For foo use the {{foo}} version.
- run: |
echo "Version: ${{ steps.draft-release.outputs.version }}"
echo "Previous Version: ${{ steps.draft-release.outputs.previous-version }}"
echo "Release Notes: ${{ steps.draft-release.outputs.release-notes }}"
echo "Release URL: ${{ steps.draft-release.outputs.release-url }}"
echo "Release ID: ${{ steps.draft-release.outputs.release-id }}"
echo "Release Sections: ${{ steps.draft-release.outputs.release-sections }}"
4 changes: 4 additions & 0 deletions __tests__/notes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ describe('generateReleaseNotes', () => {
variables: ['foo=bar', 'baz=qux'],
collapseAfter: 0,
publish: false,
configPath: '',
dryRun: false,
}
const releaseData = {
releases: [],
Expand Down Expand Up @@ -119,6 +121,8 @@ describe('generateReleaseNotes', () => {
variables: [],
collapseAfter: 3,
publish: false,
configPath: '',
dryRun: false,
}

const releaseData = {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ describe('createOrUpdateRelease', () => {
variables: [],
collapseAfter: 0,
publish: false,
configPath: '',
dryRun: false,
}
beforeEach(() => {
jest.clearAllMocks()
Expand Down
2 changes: 2 additions & 0 deletions __tests__/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe('getVersionIncrease', () => {
variables: [],
collapseAfter: 0,
publish: false,
configPath: '',
dryRun: false,
}

const releaseData = {
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ inputs:
description: 'Whether to publish the release'
default: 'false'
required: false
config-path:
description: 'Path to the configuration file'
default: ''
required: false
dry-run:
description: 'Whether to run the action without creating a release'
default: 'false'
required: false
outputs:
version:
description: 'The version of the release'
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface Inputs {
variables: string[]
collapseAfter: number
publish: boolean
configPath: string
dryRun: boolean
}

export function getInputs(): Inputs {
Expand All @@ -22,5 +24,7 @@ export function getInputs(): Inputs {
variables: Util.getInputList('variables'),
collapseAfter: parseInt(core.getInput('collapse-after'), 10),
publish: core.getBooleanInput('publish'),
configPath: core.getInput('config-path'),
dryRun: core.getBooleanInput('dry-run'),
}
}
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ async function run(): Promise<void> {
core.setOutput('version', releaseData.nextRelease)

// create or update release
await createOrUpdateRelease(client, inputs, releaseData)
if (!inputs.dryRun) {
await createOrUpdateRelease(client, inputs, releaseData)
}
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
Expand Down
1 change: 1 addition & 0 deletions src/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function generateReleaseNotes(
tag_name: nextRelease,
previous_tag_name: semver.gt(latestRelease, '0.0.0') ? latestRelease : '',
target_commitish: releaseData.branch,
configuration_file_path: inputs.configPath,
})

body = notes.data.body
Expand Down

0 comments on commit bee1f30

Please sign in to comment.