-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (81 loc) · 3.38 KB
/
create-changeset.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
name: "Create Changeset and Add Release Label"
on:
pull_request_target:
types:
- opened
- edited
- synchronize
jobs:
changeset:
name: Create Changeset and Add Release Label
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Determine Release Type
id: determine-release
run: |
PR_NUMBER=$(jq -r .number "$GITHUB_EVENT_PATH")
RELEASE_TYPE="patch"
LABELS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/labels" | jq -r '.[].name')
echo "Labels on PR: $LABELS"
for LABEL in $LABELS; do
if [ "$LABEL" == "Release Type: Major" ]; then
RELEASE_TYPE="major"
break
elif [ "$LABEL" == "Release Type: Minor" ]; then
RELEASE_TYPE="minor"
fi
done
echo "release_type=$RELEASE_TYPE" >> $GITHUB_ENV
echo "changeset_type=$RELEASE_TYPE" >> $GITHUB_ENV
- name: Debug Release Type
run: echo "Determined release type: ${{ env.release_type }}"
- name: Create Changeset
run: |
PR_TITLE=$(jq -r .title "$GITHUB_EVENT_PATH")
TYPE=${{ env.changeset_type }}
WORDS=("mushroom" "pepperoni" "pineapple" "bacon" "cheese" "olives" "peppers" "sausage" "onions" "spinach" "tomato" "ham" "chicken" "beef" "jalapeno" "broccoli" "anchovies" "artichoke" "garlic" "basil")
COOK_TIMES=("10min" "12min" "15min" "18min" "20min")
TEMPERATURES=("350F" "375F" "400F" "425F")
RANDOM_WORD1=${WORDS[$RANDOM % ${#WORDS[@]}]}
RANDOM_WORD2=${WORDS[$RANDOM % ${#WORDS[@]}]}
RANDOM_TIME=${COOK_TIMES[$RANDOM % ${#COOK_TIMES[@]}]}
RANDOM_TEMP=${TEMPERATURES[$RANDOM % ${#TEMPERATURES[@]}]}
TIMESTAMP=$(date +%s)
FILENAME="${RANDOM_WORD1}-${RANDOM_WORD2}-${RANDOM_TIME}-${RANDOM_TEMP}-${TIMESTAMP}.md"
mkdir -p .changeset
echo "---" > .changeset/$FILENAME
echo "$TYPE: $TYPE" >> .changeset/$FILENAME
echo "---" >> .changeset/$FILENAME
echo "" >> .changeset/$FILENAME
echo "$PR_TITLE" >> .changeset/$FILENAME
echo "" >> .changeset/$FILENAME
echo "_This changeset was automatically generated._" >> .changeset/$FILENAME
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Commit Changeset
run: |
git add .changeset/$FILENAME
git commit -m "chore: add changeset for $PR_TITLE"
- name: Push Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin HEAD:${{ github.head_ref }}
- name: Add Release Label
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [ "${{ env.release_type }}" ]
})