-
Notifications
You must be signed in to change notification settings - Fork 75
145 lines (125 loc) · 5.16 KB
/
snapshot-release.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
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
name: Snapshot Release
on:
issue_comment:
types:
- created
jobs:
release_next:
name: release:next
runs-on: ubuntu-latest
# Permissions necessary for Changesets to push a new branch and open PRs
# (for automated Version Packages PRs), and request the JWT for provenance.
# More info: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings
permissions:
contents: write
pull-requests: write
id-token: write
if: |
github.repository == 'siemens/ix' &&
github.event.issue.pull_request &&
(
github.event.sender.login == 'danielleroux' ||
github.event.sender.login == 'nuke-ellington'
) &&
startsWith(github.event.comment.body, '/release:pr')
steps:
- uses: alessbell/[email protected]
id: comment-branch
- name: Get sha
id: parse-sha
continue-on-error: true
run: |
if [ "${{ steps.comment-branch.outputs.head_owner }}" == "siemens" ]; then
echo "sha=${{ steps.comment-branch.outputs.head_sha }}" >> "${GITHUB_OUTPUT}"
else
sha_from_comment="$(echo $COMMENT_BODY | tr -s ' ' | cut -d ' ' -f2)"
if [ $sha_from_comment == "/release:pr" ]; then
exit 1
else
echo "sha=$sha_from_comment" >> "${GITHUB_OUTPUT}"
fi
fi
env:
COMMENT_BODY: ${{ github.event.comment.body }}
- name: Comment sha reminder
if: steps.parse-sha.outcome == 'failure'
uses: peter-evans/[email protected]
with:
issue-number: ${{ github.event.issue.number }}
body: |
Did you forget to add the SHA? Please use `/release:pr <sha>`
- name: Fail job
if: steps.parse-sha.outcome == 'failure'
run: |
exit 1
- name: Checkout ref
uses: actions/checkout@v4
with:
## specify the owner + repository in order to checkout the fork
## for community PRs
repository: ${{ steps.comment-branch.outputs.head_owner }}/${{ steps.comment-branch.outputs.head_repo }}
ref: ${{ steps.parse-sha.outputs.sha }}
fetch-depth: 0
- name: Detect new changesets
id: added-files
run: |
delimiter="$(openssl rand -hex 8)"
echo "changesets<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "$(git diff --name-only --diff-filter=A ${{ steps.comment-branch.outputs.base_sha }} ${{ steps.parse-sha.outputs.sha }} .changeset/*.md)" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
- uses: ./.github/workflows/actions/turbo
- name: Check for pre.json file existence
id: check_files
uses: andstor/[email protected]
with:
files: '.changeset/pre.json'
- name: Exit pre mode if pre.json exists
# Changesets prevents us from generating a snapshot release
# if we're in prerelease mode, so we remove `pre.json` if it exists
# (but do not commit this change since we want the branch to remain
# in pre mode)
if: steps.check_files.outputs.files_exists == 'true'
run: rm .changeset/pre.json
- name: Add comment if no new changeset exists
if: ${{ steps.added-files.outputs.changesets == '' }}
uses: peter-evans/[email protected]
with:
issue-number: ${{ github.event.issue.number }}
body: |
Please add a changeset via `pnpm changeset` before attempting a snapshot release.
- name: Release to pr tag
if: ${{ steps.added-files.outputs.changesets != '' }}
run: |
pnpm changeset version --snapshot pr-${{ github.event.issue.number }} && pnpm i --lockfile-only
pnpm build --filter \!documentation
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
pnpm changeset publish --no-git-tag --snapshot --tag snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get released version
if: ${{ steps.added-files.outputs.changesets != '' }}
id: get-version
run: echo "version=$(node -p "require('./packages/core/package.json').version")" >> "$GITHUB_OUTPUT"
- name: Create comment
if: ${{ steps.added-files.outputs.changesets != '' }}
uses: peter-evans/[email protected]
with:
issue-number: ${{ github.event.issue.number }}
body: |
A new release has been made for this PR. You can install it with:
Core library:
```
npm i @siemens/ix@${{ steps.get-version.outputs.version }}
```
Angular:
```
npm i @siemens/ix-angular@${{ steps.get-version.outputs.version }}
```
React:
```
npm i @siemens/ix-react@${{ steps.get-version.outputs.version }}
```
Vue:
```
npm i @siemens/ix-vue@${{ steps.get-version.outputs.version }}
```