diff --git a/.github/workflows/bump.overlay.yml b/.github/workflows/bump.overlay.yml new file mode 100644 index 0000000..6978484 --- /dev/null +++ b/.github/workflows/bump.overlay.yml @@ -0,0 +1,138 @@ +name: bump +on: + workflow_call: + inputs: + bumpAmount: + type: string + required: false + default: patch + description: Semver segment to bump (→ v[major].[minor].[patch]) + releaseBranch: + type: string + required: false + default: main + description: The branch that will create release tags + initialReleaseTitle: + type: string + required: false + default: '[Initial release] {0}/{1} {2}' + description: 'Formats: {0} = repoOwner, {1} = repoName, {2} = newTag' + releaseTitle: + type: string + required: false + default: '{0}/{1} {3}' + description: 'Formats: {0} = repoOwner, {1} = repoName, {2} = oldTag, {3} = newTag' + initialReleaseBody: + type: string + required: false + default: '[[{2}](https://github.com/{0}/{1}/tree/{2})' + description: '{0} = repoOwner, {1} = repoName, {2} = newTag' + releaseBody: + type: string + required: false + default: '[{2}](https://github.com/{0}/{1}/tree/{2}) [→](https://github.com/{0}/{1}/compare/{2}...{3}) [{3}](https://github.com/{0}/{1}/tree/{3})' + description: '{0} = repoOwner, {1} = repoName, {2} = oldTag, {3} = newTag' + makeLatest: + type: string + required: false + default: true + outputs: + oldTag: + description: Name of the old tag used for relative bumping + value: ${{ jobs.job.outputs.oldTag }} + newTag: + description: Name of the newly created git tag + value: ${{ jobs.job.outputs.newTag }} + newSemver: + description: Semver notation of the newly created git tag + value: ${{ jobs.job.outputs.newSemver }} + releaseId: + description: GitHub API ID of newly created release + value: ${{ jobs.job.outputs.releaseId }} + releaseUrl: + description: HTML link to newly created release + value: ${{ jobs.job.outputs.releaseUrl }} + releaseTitle: + description: Title of the newly created release with string interpolation applied + value: ${{ jobs.job.outputs.releaseTitle }} + releaseBody: + description: Description of the newly created release with string interpolation applied + value: ${{ jobs.job.outputs.releaseBody }} +jobs: + job: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: checkout + uses: actions/checkout@v3.5.2 + with: + fetch-depth: 0 + - name: setupNode + uses: actions/setup-node@v3.6.0 + with: + node-version: current + - name: installNodePackages + shell: bash + run: | + cd .. + npm install --no-package-lock --no-save @actions/core + - name: createTag + id: createTag + uses: anothrNick/github-tag-action@1.65.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + DEFAULT_BUMP: ${{ inputs.bumpAmount }} + RELEASE_BRANCHES: ${{ inputs.releaseBranch }} + - name: extractSemvers + id: extractSemvers + shell: sh -c "node --input-type module < {0}" + env: + steps: ${{ toJson(steps) }} + run: | + import core from '@actions/core' + const steps = JSON.parse(process.env.steps) + const extractSemver = tag => { + return /(?v?)(?\d+\.\d+\.\d+)/.exec(tag)?.groups + } + const newSemver = extractSemver(steps.createTag.outputs.new_tag) + console.dir({ + newTag: steps.createTag.outputs.new_tag, + newSemver + }) + core.setOutput('newSemver', newSemver?.version) + - name: getReleaseTexts + id: getReleaseTexts + shell: bash + env: + oldTag: ${{ steps.createTag.outputs.old_tag }} + releaseTitle: ${{ format(inputs.releaseTitle, github.repository_owner, github.event.repository.name, steps.createTag.outputs.old_tag, steps.createTag.outputs.new_tag) }} + releaseBody: ${{ format(inputs.releaseBody, github.repository_owner, github.event.repository.name, steps.createTag.outputs.old_tag, steps.createTag.outputs.new_tag) }} + initialReleaseTitle: ${{ format(inputs.initialReleaseTitle, github.repository_owner, github.event.repository.name, steps.createTag.outputs.new_tag) }} + initialReleaseBody: ${{ format(inputs.initialReleaseBody, github.repository_owner, github.event.repository.name, steps.createTag.outputs.new_tag) }} + run: | + if [[ -n $oldTag ]]; then + printf title=%s "$releaseTitle" > $GITHUB_OUTPUT + printf '\nbody=%s' "$releaseBody" >> $GITHUB_OUTPUT + else + printf title=%s "$initialReleaseTitle" > $GITHUB_OUTPUT + printf '\nbody=%s' "$initialReleaseBody" >> $GITHUB_OUTPUT + fi + - name: updateRelease + id: updateRelease + uses: ncipollo/release-action@v1.12.0 + with: + allowUpdates: true + name: ${{ steps.getReleaseTexts.outputs.title }} + body: ${{ steps.getReleaseTexts.outputs.body }} + tag: ${{ steps.createTag.outputs.new_tag }} + makeLatest: ${{ inputs.makeLatest }} + outputs: + oldTag: ${{ steps.createTag.outputs.old_tag }} + newTag: ${{ steps.createTag.outputs.new_tag }} + newSemver: ${{ steps.extractSemvers.outputs.newSemver }} + releaseId: ${{ steps.updateRelease.outputs.id }} + releaseUrl: ${{ steps.updateRelease.outputs.html_url }} + releaseTitle: ${{ steps.getReleaseTexts.outputs.title }} + releaseBody: ${{ steps.getReleaseTexts.outputs.body }} \ No newline at end of file diff --git a/.github/workflows/bump.yml b/.github/workflows/bump.yml index e4cf794..5ad0ccb 100644 --- a/.github/workflows/bump.yml +++ b/.github/workflows/bump.yml @@ -18,6 +18,6 @@ jobs: name: ${{ github.workflow }} permissions: contents: write - uses: jaid/workflows/.github/workflows/bump.yml@main + uses: ./.github/workflows/bump.overlay.yml with: bumpAmount: ${{ inputs.bumpAmount }} diff --git a/.github/workflows/debug.overlay.yml b/.github/workflows/debug.overlay.yml index 899294e..0dbb249 100644 --- a/.github/workflows/debug.overlay.yml +++ b/.github/workflows/debug.overlay.yml @@ -7,6 +7,15 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: + - name: setupNode + uses: actions/setup-node@v3.6.0 + with: + node-version: current + - name: installNodePackages + shell: bash + run: | + cd .. + npm install --no-package-lock --no-save @actions/core @actions/github yaml - name: prepare id: prepare shell: bash @@ -91,6 +100,25 @@ jobs: run: | set -o xtrace jq --indent 2 --color-output . <<< "$object" + - name: "* from '@actions/github'" + shell: sh -c "node --input-type module < {0}" + run: |- + import core from '@actions/core' + import * as github from '@actions/github' + import yaml from 'yaml' + const toYaml = input => yaml.stringify(input, null, { + schema: 'core', + lineWidth: 0, + minContentWidth: 0, + singleQuote: true, + nullStr: '~' + }) + core.startGroup('all as dir') + console.dir(github) + core.endGroup() + core.startGroup('context as yaml') + console.log(toYaml(github.context)) + core.endGroup() - name: env shell: bash run: | diff --git a/.vscode/settings.json b/.vscode/settings.json index a13c495..b2d645b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,6 @@ "explorer.fileNesting.patterns": { "debug.yml": "debug.overlay.yml", "pushDocker.yml": "pushDocker.*,testDocker.*,makeDockerTagMatrix.*,buildDocker.*,uploadDocker.*,executePushDocker.*,getDockerImageName.*", + "bump.yml": "bump.*" }, } \ No newline at end of file