1+ name : Automated Release
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ jobs :
9+ release :
10+ if : contains(github.event.head_commit.message, '[patch]') || contains(github.event.head_commit.message, '[minor]') || contains(github.event.head_commit.message, '[major]')
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - name : Checkout code
15+ uses : actions/checkout@v4
16+ with :
17+ fetch-depth : 0
18+ token : ${{ secrets.GITHUB_TOKEN }}
19+
20+ - name : Setup Node.js
21+ uses : actions/setup-node@v4
22+ with :
23+ node-version : ' 20'
24+ registry-url : ' https://registry.npmjs.org'
25+
26+ - name : Install dependencies
27+ run : npm ci
28+
29+ - name : Determine version bump type
30+ id : bump-type
31+ run : |
32+ if [[ "${{ github.event.head_commit.message }}" == *"[major]"* ]]; then
33+ echo "type=major" >> $GITHUB_OUTPUT
34+ elif [[ "${{ github.event.head_commit.message }}" == *"[minor]"* ]]; then
35+ echo "type=minor" >> $GITHUB_OUTPUT
36+ else
37+ echo "type=patch" >> $GITHUB_OUTPUT
38+ fi
39+
40+ - name : Get current version
41+ id : current-version
42+ run : |
43+ CURRENT_VERSION=$(node -p "require('./package.json').version")
44+ echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
45+
46+ - name : Calculate new version
47+ id : new-version
48+ run : |
49+ CURRENT="${{ steps.current-version.outputs.version }}"
50+ TYPE="${{ steps.bump-type.outputs.type }}"
51+
52+ # Parse version numbers
53+ IFS='.' read -ra VERSION_PARTS <<< "$CURRENT"
54+ MAJOR=${VERSION_PARTS[0]}
55+ MINOR=${VERSION_PARTS[1]}
56+ PATCH=${VERSION_PARTS[2]}
57+
58+ case $TYPE in
59+ major)
60+ NEW_VERSION="$((MAJOR + 1)).0.0"
61+ ;;
62+ minor)
63+ NEW_VERSION="$MAJOR.$((MINOR + 1)).0"
64+ ;;
65+ patch)
66+ NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
67+ ;;
68+ esac
69+
70+ echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
71+
72+ - name : Update package.json version
73+ run : |
74+ npm version ${{ steps.new-version.outputs.version }} --no-git-tag-version
75+
76+ - name : Build package
77+ run : npm run package
78+
79+ - name : Publish to npm
80+ run : npm publish
81+ env :
82+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
83+
84+ - name : Create git tag
85+ run : |
86+ git config --local user.email "[email protected] " 87+ git config --local user.name "GitHub Action"
88+ git tag "v${{ steps.new-version.outputs.version }}"
89+ git push origin "v${{ steps.new-version.outputs.version }}"
90+
91+ - name : Create GitHub release
92+ uses : actions/create-release@v1
93+ env :
94+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
95+ with :
96+ tag_name : v${{ steps.new-version.outputs.version }}
97+ release_name : Release v${{ steps.new-version.outputs.version }}
98+ body : |
99+ Automated release v${{ steps.new-version.outputs.version }}
100+
101+ Changes in this release:
102+ - ${{ github.event.head_commit.message }}
0 commit comments