|
1 | | -name: Build and Release |
| 1 | +name: CI |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
|
7 | 7 | branches: [main] |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - build: |
| 10 | + test-and-build: |
11 | 11 | runs-on: ubuntu-latest |
12 | 12 |
|
13 | 13 | steps: |
|
23 | 23 | - name: Install dependencies |
24 | 24 | run: npm ci |
25 | 25 |
|
26 | | - - name: Run linting |
27 | | - run: npm run lint |
28 | | - |
29 | 26 | - name: Build application |
30 | 27 | run: npm run build |
31 | | - |
32 | | - release: |
33 | | - needs: build |
34 | | - runs-on: ubuntu-latest |
35 | | - if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
36 | | - |
37 | | - permissions: |
38 | | - contents: write |
39 | | - |
40 | | - steps: |
41 | | - - name: Checkout repository |
42 | | - uses: actions/checkout@v4 |
43 | | - with: |
44 | | - fetch-depth: 0 |
45 | | - token: ${{ secrets.GITHUB_TOKEN }} |
46 | | - |
47 | | - - name: Setup Node.js |
48 | | - uses: actions/setup-node@v4 |
49 | | - with: |
50 | | - node-version: "20.x" |
51 | | - cache: "npm" |
52 | | - |
53 | | - - name: Configure Git |
54 | | - run: | |
55 | | - git config user.name "github-actions[bot]" |
56 | | - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
57 | | -
|
58 | | - - name: Bump version and update changelog |
59 | | - run: | |
60 | | - # Get commit messages since last tag |
61 | | - COMMIT_MESSAGES=$(git log --pretty=format:"%s" $(git describe --tags --abbrev=0 2>/dev/null || echo "HEAD~10")..HEAD) |
62 | | -
|
63 | | - # Determine version bump type based on commit messages |
64 | | - if echo "$COMMIT_MESSAGES" | grep -qE "^major(\(.+\))?:"; then |
65 | | - BUMP_TYPE="major" |
66 | | - elif echo "$COMMIT_MESSAGES" | grep -qE "^feat(\(.+\))?:"; then |
67 | | - BUMP_TYPE="minor" |
68 | | - else |
69 | | - BUMP_TYPE="patch" |
70 | | - fi |
71 | | -
|
72 | | - echo "Detected bump type: $BUMP_TYPE" |
73 | | -
|
74 | | - # Bump version |
75 | | - npm version $BUMP_TYPE --no-git-tag-version |
76 | | - NEW_VERSION=$(node -p "require('./package.json').version") |
77 | | -
|
78 | | - # Generate changelog entry with commit details |
79 | | - DATE=$(date +"%Y-%m-%d") |
80 | | - CHANGELOG_ENTRY="## [$NEW_VERSION] - $DATE\n\n" |
81 | | -
|
82 | | - # Add commits to changelog |
83 | | - while IFS= read -r commit; do |
84 | | - if [ ! -z "$commit" ]; then |
85 | | - CHANGELOG_ENTRY="${CHANGELOG_ENTRY}- $commit\n" |
86 | | - fi |
87 | | - done <<< "$COMMIT_MESSAGES" |
88 | | -
|
89 | | - CHANGELOG_ENTRY="${CHANGELOG_ENTRY}\n" |
90 | | -
|
91 | | - # Update CHANGELOG.md |
92 | | - if [ -f "CHANGELOG.md" ]; then |
93 | | - sed -i "3i\\$CHANGELOG_ENTRY" CHANGELOG.md |
94 | | - else |
95 | | - echo -e "# Changelog\n\n$CHANGELOG_ENTRY" > CHANGELOG.md |
96 | | - fi |
97 | | -
|
98 | | - # Commit and push |
99 | | - git add package.json CHANGELOG.md |
100 | | - git commit -m "chore: bump version to v$NEW_VERSION [skip ci]" |
101 | | - git tag "v$NEW_VERSION" |
102 | | - git push origin main |
103 | | - git push origin "v$NEW_VERSION" |
0 commit comments