-
Notifications
You must be signed in to change notification settings - Fork 5
112 lines (94 loc) · 3.21 KB
/
cd.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
name: Release workflow
on:
schedule:
- cron: '0 0 * * *'
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
actions: read
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install yarn
run: npm install -g yarn
- name: Install Dependencies
run: yarn
- name: Run build
run: yarn build
- name: Generate release notes
run: |
git log --pretty=format:"%h - %s (%an)" $(git log -G '"version":' -n 2 --pretty=format:%H -- package.json | sed -n 2p)..HEAD
GIT_LOG=$(git log --pretty=format:"%h - %s (%an)" $(git log -G '"version":' -n 2 --pretty=format:%H -- package.json | sed -n 2p)..HEAD)
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "${GIT_LOG}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Check if tag is present
id: tag_check
run: |
VERSION=$(jq -r '.version' package.json)
echo "version=${VERSION}" >> $GITHUB_ENV
if git rev-parse "${VERSION}" >/dev/null 2>&1; then
echo "Tag v${VERSION} already exists."
echo "exists=true" >> $GITHUB_ENV
else
echo "Tag v${VERSION} does not exist."
echo "exists=false" >> $GITHUB_ENV
fi
- name: Create npm package
run: yarn pack
- name: Checkout release branch
uses: actions/checkout@v4
with:
ref: release
path: ./release
fetch-depth: 0
- name: Extract package contents
run: |
tar -xzf *.tgz --strip-components=1 -C ./release
- name: Push package contents to a new branch
if: env.exists == 'false'
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
cd ./release
git add .
CHANGED_FILES=$(git diff-index HEAD)
if [ -n "$CHANGED_FILES" ]; then
echo "Pushing with message: Release v${{ env.version }}"
git commit -m "Release v${{ env.version }}"
echo "Pushing with message: Release v${{ env.version }}"
git push origin release
echo "skip_release=false" >> $GITHUB_ENV
else
echo "No changes to push"
echo "skip_release=true" >> $GITHUB_ENV
fi
- name: Printing release notes
run: |
echo " ${{ env.RELEASE_NOTES }} "
echo v${{ env.version }}
echo ${{ env.exists }}
- name: Create Release
if: env.exists == 'false' && env.skip_release == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.version }}
release_name: Release v${{ env.version }}
body: ${{ env.RELEASE_NOTES }}
draft: false
prerelease: false
commitish: release