forked from reactioncommerce/reaction
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (127 loc) · 4.79 KB
/
prerelease.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
name: PRERELEASE
on:
workflow_dispatch:
pull_request:
branches:
- prerelease
types:
- closed
permissions: {}
jobs:
version:
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/prerelease'
permissions:
contents: write # to create release (changesets/action)
pull-requests: write # to create pull request (changesets/action)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
key: reaction-v6-node-modules-${{ hashFiles('package.json') }}-${{ hashFiles('pnpm-lock.yaml') }}
path: "**/node_modules"
- name: Use Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: "18.18.2"
- name: Install pnpm
run: npm i -g [email protected]
- name: Install dependencies
run: pnpm install --ignore-scripts
- name: Enter prerelease mode
run: pnpm changeset pre enter next || true
- name: Check should create release
id: should-create-release
run: |
if [[ $(cat ./.changeset/pre.json | grep -m 1 mode | sed 's/[^a-z]//g') == *"pre"* ]]; then
echo "RESULT=true" >> $GITHUB_OUTPUT
else
echo "RESULT=false" >> $GITHUB_OUTPUT
fi
- name: Create Release Pull Request or Publish to npm
id: changesets
if: steps.should-create-release.outputs.RESULT == 'true'
uses: changesets/action@v1
with:
publish: pnpm changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Update pnpm-lock.yaml
id: update-lock-file
if: github.event_name == 'workflow_dispatch'
run: |
pnpm install --ignore-scripts --lockfile-only
if [[ $(git status --porcelain | grep -m 1 pnpm-lock.yaml | sed 's/[^a-z]\-//g') == *"pnpm-lock.yaml"* ]]; then
echo "IS_CHANGED=true" >> $GITHUB_OUTPUT
else
echo "IS_CHANGED=false" >> $GITHUB_OUTPUT
fi
- name: Commit pnpm-lock.yaml
if: steps.update-lock-file.outputs.IS_CHANGED == 'true'
run: |
git config --global user.name "$(git --no-pager log --format=format:'%an' -n 1)"
git config --global user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
git add pnpm-lock.yaml
git commit -m "chore: update pnpm-lock.yaml" -s
git push -u origin changeset-release/prerelease
release:
if: github.event.pull_request.merged == true && github.base_ref == 'prerelease' && github.head_ref == 'changeset-release/prerelease'
permissions:
contents: write # to create release (changesets/action)
pull-requests: write # to create pull request (changesets/action)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: "18.18.2"
- name: Install pnpm
run: npm i -g [email protected]
- name: Install dependencies
run: pnpm install --ignore-scripts
- name: Enter prerelease mode
run: pnpm changeset pre enter next || true
- name: Check should create release
id: should-create-release
run: |
if [[ $(cat ./.changeset/pre.json | grep -m 1 mode | sed 's/[^a-z]//g') == *"pre"* ]]; then
echo "RESULT=true" >> $GITHUB_OUTPUT
else
echo "RESULT=false" >> $GITHUB_OUTPUT
fi
- name: Create Release Pull Request or Publish to npm
id: changesets
if: steps.should-create-release.outputs.RESULT == 'true'
uses: changesets/action@v1
with:
publish: pnpm changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Exit prerelease mode
id: exit-prerelease-mode
run: |
rm ./.changeset/pre.json
if [[ $(git status --porcelain | grep -m 1 pre.json | sed 's/[^a-z]\-//g') == *"pre.json"* ]]; then
echo "IS_CHANGED=true" >> $GITHUB_OUTPUT
else
echo "IS_CHANGED=false" >> $GITHUB_OUTPUT
fi
- name: Commit pre.json
if: steps.exit-prerelease-mode.outputs.IS_CHANGED == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .changeset/pre.json
git commit -m "chore: exit prerelease mode" -s
git push origin prerelease