-
Notifications
You must be signed in to change notification settings - Fork 9
162 lines (149 loc) · 6.92 KB
/
create-github-release.yml
File metadata and controls
162 lines (149 loc) · 6.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: create-github-release
on:
workflow_call:
secrets:
SVC_CLI_BOT_GITHUB_TOKEN:
description: A Github PAT with repo write access.
required: true
CLI_ALERTS_SLACK_WEBHOOK:
description: Slack webhook for alerts.
required: false
inputs:
prerelease:
type: string
description: "Name to use for the prerelease: beta, dev, etc."
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: Generate oclif readme
if: ${{ inputs.generate-readme }}
uses: salesforcecli/github-workflows/.github/actions/generateOclifReadme@main
with:
skip-on-empty: ${{ inputs.skip-on-empty }}
pre-release: ${{ steps.prereleaseTag.outputs.tag && 'true' || 'false' }}
pre-release-identifier: ${{ steps.prereleaseTag.outputs.tag }}
multi: ${{ inputs.readme-multi }}
- 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 }}
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
# Determine if we should alert Slack that the release was skipped.
# Skip the alert if: no webhook is configured, or the commit is from a Dependabot merge.
- name: Should we post to Slack that release was skipped
id: should-post-slack
if: steps.changelog.outputs.skipped == 'true'
run: |
if [ -z "$SLACK_WEBHOOK" ]; then
echo "[INFO] No Slack webhook configured, skipping alert"
exit 0
fi
PR_AUTHOR=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" --jq '.[0].user.login // empty')
echo "[INFO] PR author: $PR_AUTHOR"
if [ "$PR_AUTHOR" = "dependabot[bot]" ]; then
echo "[INFO] Dependabot merge, skipping alert"
exit 0
fi
echo "post_skipped_release_to_slack=true" >> "$GITHUB_OUTPUT"
env:
SLACK_WEBHOOK: ${{ secrets.CLI_ALERTS_SLACK_WEBHOOK }}
GH_TOKEN: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }}
- name: Announce if Github Release was skipped
id: slack
if: steps.should-post-slack.outputs.post_skipped_release_to_slack == 'true'
uses: slackapi/slack-github-action@v1.26.0
env:
# for non-CLI-team-owned plugins, you can send this anywhere you like
SLACK_WEBHOOK_URL: ${{ secrets.CLI_ALERTS_SLACK_WEBHOOK }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
# Payload can be visually tested here: https://app.slack.com/block-kit-builder/T01GST6QY0G#%7B%22blocks%22:%5B%5D%7D
# Only copy over the "blocks" array to the Block Kit Builder
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":uno-skip-red: Github Release was skipped in ${{ github.repository }}! :uno-skip-red:"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Repo:* ${{ github.server_url }}/${{ github.repository }}\n*Workflow name:* `${{ github.workflow }}`\n*Run url:* ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
}
]
}