Skip to content

Commit 6ba49fb

Browse files
ci: add snapshot workflow (#70)
1 parent af51683 commit 6ba49fb

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

.github/workflows/snapshot.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Snapshot Release
2+
3+
on:
4+
issue_comment:
5+
types:
6+
- created
7+
8+
jobs:
9+
release_next:
10+
name: release:next
11+
runs-on: ubuntu-latest
12+
# Permissions necessary for Changesets to push a new branch and open PRs
13+
# (for automated Version Packages PRs), and request the JWT for provenance.
14+
# More info: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
id-token: write
19+
if: |
20+
github.repository == 'siemens/ix-icons' &&
21+
github.event.issue.pull_request &&
22+
(
23+
github.event.sender.login == 'danielleroux' ||
24+
github.event.sender.login == 'nuke-ellington'
25+
) &&
26+
startsWith(github.event.comment.body, '/release:pr')
27+
28+
steps:
29+
- uses: alessbell/[email protected]
30+
id: comment-branch
31+
32+
- name: Get sha
33+
id: parse-sha
34+
continue-on-error: true
35+
run: |
36+
if [ "${{ steps.comment-branch.outputs.head_owner }}" == "siemens" ]; then
37+
echo "sha=${{ steps.comment-branch.outputs.head_sha }}" >> "${GITHUB_OUTPUT}"
38+
else
39+
sha_from_comment="$(echo $COMMENT_BODY | tr -s ' ' | cut -d ' ' -f2)"
40+
41+
if [ $sha_from_comment == "/release:pr" ]; then
42+
exit 1
43+
else
44+
echo "sha=$sha_from_comment" >> "${GITHUB_OUTPUT}"
45+
fi
46+
fi
47+
env:
48+
COMMENT_BODY: ${{ github.event.comment.body }}
49+
50+
- name: Comment sha reminder
51+
if: steps.parse-sha.outcome == 'failure'
52+
uses: peter-evans/[email protected]
53+
with:
54+
issue-number: ${{ github.event.issue.number }}
55+
body: |
56+
Did you forget to add the SHA? Please use `/release:pr <sha>`
57+
58+
- name: Fail job
59+
if: steps.parse-sha.outcome == 'failure'
60+
run: |
61+
exit 1
62+
63+
- name: Checkout ref
64+
uses: actions/checkout@v4
65+
with:
66+
## specify the owner + repository in order to checkout the fork
67+
## for community PRs
68+
repository: ${{ steps.comment-branch.outputs.head_owner }}/${{ steps.comment-branch.outputs.head_repo }}
69+
ref: ${{ steps.parse-sha.outputs.sha }}
70+
fetch-depth: 0
71+
72+
- name: Detect new changesets
73+
id: added-files
74+
run: |
75+
delimiter="$(openssl rand -hex 8)"
76+
echo "changesets<<${delimiter}" >> "${GITHUB_OUTPUT}"
77+
echo "$(git diff --name-only --diff-filter=A ${{ steps.comment-branch.outputs.base_sha }} ${{ steps.parse-sha.outputs.sha }} .changeset/*.md)" >> "${GITHUB_OUTPUT}"
78+
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
79+
80+
- uses: ./.github/workflows/actions/turbo
81+
82+
- name: Check for pre.json file existence
83+
id: check_files
84+
uses: andstor/[email protected]
85+
with:
86+
files: '.changeset/pre.json'
87+
88+
- name: Exit pre mode if pre.json exists
89+
# Changesets prevents us from generating a snapshot release
90+
# if we're in prerelease mode, so we remove `pre.json` if it exists
91+
# (but do not commit this change since we want the branch to remain
92+
# in pre mode)
93+
if: steps.check_files.outputs.files_exists == 'true'
94+
run: rm .changeset/pre.json
95+
96+
- name: Add comment if no new changeset exists
97+
if: ${{ steps.added-files.outputs.changesets == '' }}
98+
uses: peter-evans/[email protected]
99+
with:
100+
issue-number: ${{ github.event.issue.number }}
101+
body: |
102+
Please add a changeset via `pnpm changeset` before attempting a snapshot release.
103+
104+
- name: Release to pr tag
105+
if: ${{ steps.added-files.outputs.changesets != '' }}
106+
run: |
107+
pnpm changeset version --snapshot pr-${{ github.event.issue.number }} && pnpm i --lockfile-only
108+
pnpm build
109+
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
110+
pnpm changeset publish --no-git-tag --snapshot --tag snapshot
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113+
114+
- name: Get released version
115+
if: ${{ steps.added-files.outputs.changesets != '' }}
116+
id: get-version
117+
run: echo "version=$(node -p "require('./packages/core/package.json').version")" >> "$GITHUB_OUTPUT"
118+
119+
- name: Create comment
120+
if: ${{ steps.added-files.outputs.changesets != '' }}
121+
uses: peter-evans/[email protected]
122+
with:
123+
issue-number: ${{ github.event.issue.number }}
124+
body: |
125+
A new release has been made for this PR. You can install it with:
126+
127+
```
128+
npm i @siemens/ix-icons@${{ steps.get-version.outputs.version }}
129+
```

0 commit comments

Comments
 (0)