-
Notifications
You must be signed in to change notification settings - Fork 7
102 lines (87 loc) · 3.27 KB
/
npm-version.yaml
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
name: Automated npm version
on:
workflow_dispatch:
inputs:
newversion:
description: New version (X.Y.Z | major | minor | patch | premajor | preminor | prepatch | prerelease)
required: true
default: patch
permissions:
contents: write
pull-requests: write
jobs:
npm-version:
name: npm version
runs-on: ubuntu-20.04
environment: automated
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Get npm cache directory
run: echo "npm_cache_dir=$(npm config get cache)" >> ${GITHUB_ENV}
- name: Use cache
uses: actions/cache@v4
with:
path: ${{ env.npm_cache_dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies for plugin
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 3
retry_on: error
command: npm ci
- name: Set version
run: |
npx lerna version --no-git-tag-version --yes --loglevel=error "$newversion" | tee .github/update.log
sed -e 's/\x1b\[[0-9;]*m//g' .github/update.log > .github/pr_body.log
jq -r .version freelens/package.json > .github/version.log
version=$(cat .github/version.log)
yq -px -ox -i '.component.releases.release.["+@version"] = "'"$version"'" | .component.releases.release.["+@date"] = "'$(LC_ALL=C date +%Y-%m-%d)'"' freelens/build/metainfo.xml
env:
newversion: ${{ github.event.inputs.newversion }}
- name: Check for changes
run: |
if git diff --exit-code; then
echo "changes=false" >> $GITHUB_ENV
else
echo "changes=true" >> $GITHUB_ENV
fi
- name: Commit and push to branch
if: env.changes == 'true'
uses: EndBug/add-and-commit@v9
with:
github_token: ${{ secrets.GH_TOKEN }}
default_author: github_actions
message: Automated npm version ${{ github.event.inputs.newversion }}
new_branch: automated/npm-version
fetch: false
push: origin automated/npm-version --set-upstream --force
- name: Create pull request
id: pr
if: env.changes == 'true'
uses: devops-infra/action-pull-request@master
with:
github_token: ${{ secrets.GH_TOKEN }}
target_branch: main
label: automated
title: Automated npm version v${{ github.event.inputs.newversion }}
get_diff: false
- name: Update pull request description
if: env.changes == 'true'
run: gh pr edit ${{ steps.pr.outputs.pr_number }} --title "Automated npm version v$(cat .github/version.log)" --body-file .github/pr_body.log
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Close pull request
if: env.changes == 'false'
run: gh pr list --head automated/npm-version --json number --jq '.[].number' | xargs -rn1 gh pr close --delete-branch
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}