-
Notifications
You must be signed in to change notification settings - Fork 1
63 lines (56 loc) · 1.95 KB
/
npm-semver-version.yml
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
name: 'NPM SemVer version'
on:
pull_request:
types: [ labeled, unlabeled, opened, reopened, synchronize ]
jobs:
version:
if: contains(github.event.pull_request.labels.*.name, 'skip-release') == false
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
registry-url: 'https://npm.pkg.github.com'
scope: '@ukhomeoffice'
- name: Calculate semver value
id: calculate
uses: UKHomeOffice/sas-github-workflows/.github/actions/calculate-semver-value@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_to_highest: ${{ github.base_ref == 'main' }}
- name: Reset branch from main version
id: compare
run: |
localFile=$(cat package.json)
originFile=$(git show origin/main:package.json)
localVersion=$(echo $localFile | jq -r '.version')
originVersion=$(echo $originFile | jq -r '.version')
if [ "$localVersion" != "$originVersion" ]; then
npm --no-git-tag-version version $originVersion
fi
shell: bash
- name: Bump release version
run: |
npm version --no-git-tag ${{ steps.calculate.outputs.version }}
shell: bash
- name: Configure git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
shell: bash
- name: Commit version
run: |
git add "package.json"
git add "package-lock.json"
git commit -m "npm version ${{ steps.calculate.outputs.version }}"
git push --set-upstream origin ${{ github.head_ref }} --force