-
Notifications
You must be signed in to change notification settings - Fork 3
83 lines (81 loc) · 2.64 KB
/
auto-version.yaml
File metadata and controls
83 lines (81 loc) · 2.64 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
name: Auto Version
on:
workflow_dispatch:
inputs:
versionOverride:
type: string
description: Enter to ignore auto versioning, and instead just explicitly set a version number.
required: false
versionType:
type: choice
description: Which version should we bump (ignored if versionOverride is set)
options:
- patch
- minor
- major
workflow_call:
inputs:
versionType:
type: string
description: Which version should we bump (ignored if versionOverride is set)
required: false
default: patch
permissions:
contents: write
jobs:
tag-current-version:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Get Current Version
id: getVersion
run: echo "version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT
- name: Create Tag
uses: actions/github-script@v8
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.getVersion.outputs.version }}',
sha: context.sha
})
change-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Configure NodeJS
if: inputs.versionOverride == ''
uses: actions/setup-node@v6
with:
node-version: 20
- name: Configure Git
run: |
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
- name: Set Version
run: |
if ${{ inputs.versionOverride != '' }}; then
jq '.version = "${{ inputs.versionOverride }}"' package.json > package.json
git add package.json
git commit -m "Set version to ${{ inputs.versionOverride }}"
else
npm ci
npm version ${{ inputs.versionType }}
fi
- name: Get New Version
id: getVersion
run: echo "version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT
- name: Push changes to Git
run: git push
- name: Send Discord Message with Build Status
if: always()
uses: slackapi/slack-github-action@v2.1.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
"text": "${{ github.event.repository.name }} - Set Version to ${{ steps.getVersion.outputs.version }}"