-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (102 loc) · 3.63 KB
/
Copy pathpublish-reusable.yml
File metadata and controls
107 lines (102 loc) · 3.63 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
name: Publish reusable
on:
workflow_call:
inputs:
branch:
required: true
type: string
secrets:
PAT_FOR_TRIGGERING_BRANCH_PROTECTION:
required: true
permissions:
contents: read
jobs:
checkingVersion:
name: Checking version
runs-on: ubuntu-latest
outputs:
isRunable: ${{ fromJson(steps.package.outputs.content).version != fromJson(steps.package.outputs.content).target-version }}
newVersion: ${{ fromJson(steps.package.outputs.content)['target-version'] }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ inputs.branch }}
- name: Read package.json
id: package
uses: juliangruber/read-file-action@271ff311a4947af354c6abcd696a306553b9ec18 # v1.1.8
with:
path: ./package.json
- name: Version check
if: ${{ fromJson(steps.package.outputs.content).version == fromJson(steps.package.outputs.content).target-version }}
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
core.setFailed('Package version and target version are equivalent!')
releasing:
name: Releasing
needs: [ checkingVersion ]
if: needs.checkingVersion.outputs.isRunable == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ inputs.branch }}
- name: Setup node JS
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org
- name: Setup GIT
run: |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git config user.name "$GITHUB_ACTOR"
- name: Setup local environment
run: yarn
- name: Determine Pre-Release Status
id: prerelease_check
env:
NEW_VERSION: ${{ needs.checkingVersion.outputs.newVersion }}
run: |
if [[ "$NEW_VERSION" == *"rc"* ]]; then
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
fi
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_VERSION: ${{ needs.checkingVersion.outputs.newVersion }}
IS_PRERELEASE: ${{ steps.prerelease_check.outputs.is_prerelease }}
run: |
npm install -g npm@latest
yarn install
yarn build
if [ "$IS_PRERELEASE" == "true" ]; then
yarn release "$NEW_VERSION" --pre-release --no-plugins.@release-it/keep-a-changelog.strictLatest --ci
else
yarn release "$NEW_VERSION" --no-plugins.@release-it/keep-a-changelog.strictLatest --ci
fi
merge:
needs: [ releasing ]
if: |
startsWith(github.head_ref, 'release') &&
github.base_ref == 'master'
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_TRIGGERING_BRANCH_PROTECTION }}
steps:
- name: Checkout develop branch
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: develop
- name: Create Pull Request
run: gh pr create --base develop --head master --title "Merge 'master' into 'develop' after release" --body "Automated Pull Request to merge 'master' into 'develop' after release"
- name: Merge Pull Request
run: |
pr_number=$(gh pr list --base develop --head master --json number --jq '.[0].number')
gh pr merge "$pr_number" --merge --auto