-
Notifications
You must be signed in to change notification settings - Fork 9
96 lines (83 loc) · 3.2 KB
/
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
name: Release
on:
push:
branches:
- main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
packages: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Setup pnpm
run: sudo npm i -g [email protected]
- name: Install Dependencies
run: pnpm install
- name: Creating .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
- name: Get Open PRs Created by Bots
id: get_bot_prs
run: |
prs=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls?state=open&per_page=100" | \
jq -r '[.[] | select(.user.type == "Bot")][0] | {url: .html_url, title: .title} | @json')
echo "Found PRs: $prs"
if [[ $prs == "null" || $prs == "{}" ]]; then
echo "BOT_PR_TITLE=NULL" >> $GITHUB_ENV
else
bot_pr_title=$(echo $prs | jq -r .title)
echo "BOT_PR_TITLE=$bot_pr_title" >> $GITHUB_ENV
fi
- name: Generate Animal Title
run: |
title_case() {
echo "$1" | awk '{
for(i=1;i<=NF;i++){
$i=toupper(substr($i,1,1)) tolower(substr($i,2))
}
}1'
}
responseAdj=$(curl -s "https://gist.githubusercontent.com/pedromcunha/9e0ea328b5c320264ddcdcc5e5b6ce48/raw/5ffec8da5b4300934f9bedca2707f1d4d2845f4f/adjectives.json")
responseAnimal=$(curl -s "https://gist.githubusercontent.com/pedromcunha/d2b7f7b7e295cbafdd03af73bcd168ba/raw/c1d4b618da5051519c5d8ffce73d0ec6b018f356/animals.json")
lengthAdj=$(echo $responseAdj | jq length)
lengthAnimal=$(echo $responseAnimal | jq length)
random_index1=$(($RANDOM % lengthAdj))
random_index2=$(($RANDOM % lengthAnimal))
while [ $random_index1 -eq $random_index2 ]; do
random_index2=$(($RANDOM % length))
done
word1=$(echo $responseAdj | jq -r ".[$random_index1].name")
word2=$(echo $responseAnimal | jq -r ".[$random_index2].name")
title="$word1 $word2"
title="Release the: $(title_case "$title")!"
echo "Title is $title"
echo "RELEASE_TITLE=$title" >> $GITHUB_ENV
- name: Determine Release Title
run: |
if [[ "${{ env.BOT_PR_TITLE }}" == "null" ]]; then
echo "FINAL_RELEASE_TITLE=${{ env.RELEASE_TITLE }}" >> $GITHUB_ENV
else
echo "FINAL_RELEASE_TITLE=${{ env.BOT_PR_TITLE }}" >> $GITHUB_ENV
fi
- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1
with:
title: ${{ env.FINAL_RELEASE_TITLE }}
publish: pnpm package:release