Skip to content

Merge pull request #441 from sf-aastha-paruthi/u/aparuthi/AddToReleas… #158

Merge pull request #441 from sf-aastha-paruthi/u/aparuthi/AddToReleas…

Merge pull request #441 from sf-aastha-paruthi/u/aparuthi/AddToReleas… #158

name: create-github-release
on:
push:
branches:
- main
- prerelease/**
- release*
tags-ignore:
- '*'
workflow_dispatch:
inputs:
prerelease:
type: string
description: 'Name to use for the prerelease: beta, dev, etc. NOTE: If this is already set in the package.json, it does not need to be passed in here.'
skip-on-empty:
type: boolean
default: 'true'
description: 'Should release be skipped if there are no semantic commits?'
generate-readme:
type: boolean
default: 'true'
description: 'Generate oclif readme'
readme-multi:
type: boolean
description: 'Create a different markdown page for each topic.'
default: 'false'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Get Github user info
id: github-user-info
uses: salesforcecli/github-workflows/.github/actions/getGithubUserInfo@main
with:
SVC_CLI_BOT_GITHUB_TOKEN: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }}
- uses: actions/checkout@v4
with:
token: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }}
- uses: salesforcecli/github-workflows/.github/actions/getPreReleaseTag@main
id: distTag
- name: Validate prerelease
if: github.ref_name == 'main' && inputs.prerelease
uses: actions/github-script@v7
with:
script: |
core.setFailed('Do not create a prerelease on "main". You can create a prerelease on a branch and when it is merged it will create a non-prerelease Release. For example: 1.0.1-beta.2 will release as 1.0.1 when merged into main.')
- name: Determine prerelease name
id: prereleaseTag
# Only run this step if the ref is not main
# This will allow us to merge a prerelease PR into main and have it release as a normal release
if: github.ref_name != 'main'
run: |
if [ -n "$INPUTS_PRERELEASE" ]; then
echo "[INFO] Prerelease input passed in, using: $INPUTS_PRERELEASE"
echo "tag=$INPUTS_PRERELEASE" >> "$GITHUB_OUTPUT"
elif [ -n "$STEPS_DISTTAG_TAG" ]; then
echo "[INFO] Prerelease tag found in package.json, using: $STEPS_DISTTAG_TAG"
echo "tag=$STEPS_DISTTAG_TAG" >> "$GITHUB_OUTPUT"
elif [[ "$GITHUB_REF_NAME" =~ ^prerelease/.* ]]; then
echo "[INFO] Prerelease branch found but no prerelease tag, using default: dev"
echo "tag=dev" >> "$GITHUB_OUTPUT"
fi
env:
INPUTS_PRERELEASE: ${{ inputs.prerelease }}
STEPS_DISTTAG_TAG: ${{ steps.distTag.outputs.tag }}
- name: Conventional Changelog Action
id: changelog
uses: TriPSs/conventional-changelog-action@3a392e9aa44a72686b0fc13259a90d287dd0877c
with:
git-user-name: ${{ steps.github-user-info.outputs.username }}
git-user-email: ${{ steps.github-user-info.outputs.email }}
github-token: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }}
tag-prefix: ''
# Setting 'release-count' to 0 will keep ALL releases in the change log file (no pruning)
release-count: '0'
skip-on-empty: ${{ inputs.skip-on-empty == 'true' }}
pre-release: ${{ steps.prereleaseTag.outputs.tag != '' && 'true' || 'false' }}
pre-release-identifier: ${{ steps.prereleaseTag.outputs.tag }}
# ternary-ish: https://github.com/actions/runner/issues/409#issuecomment-752775072
output-file: ${{ steps.prereleaseTag.outputs.tag != '' && 'false' || 'CHANGELOG.md' }} # If prerelease, do not write the changelog file
- name: Create Github Release
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5
if: ${{ steps.changelog.outputs.skipped == 'false' }}
with:
name: ${{ steps.changelog.outputs.tag }}
tag: ${{ steps.changelog.outputs.tag }}
commit: ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.clean_changelog }}
prerelease: ${{ steps.prereleaseTag.outputs.tag != '' && 'true' || 'false' }}
token: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }}
skipIfReleaseExists: true
# docs:
# # Most repos won't use this
# # Depends on the 'release' job to avoid git collisions, not for any functionality reason
# needs: release
# secrets: inherit
# if: ${{ github.ref_name == 'main' }}
# uses: salesforcecli/github-workflows/.github/workflows/publishTypedoc.yml@main