-
Notifications
You must be signed in to change notification settings - Fork 1.2k
106 lines (92 loc) · 3.43 KB
/
chrome-extension-ci.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
name: chrome-extension CI
on:
push:
branches: [main]
paths:
- "extensions/chrome/**"
pull_request:
branches: [main]
paths:
- "extensions/chrome/**"
defaults:
run:
working-directory: ./extensions/chrome
jobs:
lint-and-format:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run ESLint and format fix
run: bun run fix
- name: Run markdown lint
# DON't TOUCH THIS LINE BELOW #
run: bunx markdownlint-cli2 "./**/*.md" --config .markdownlint-cli2.jsonc
test-and-build:
needs: lint-and-format
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run tests
run: bun test
- name: Build extension
run: bun run build
- name: Zip Extension
run: zip -r chrome-extension.zip dist/
# Automatically increments the patch version (e.g., 1.0.0 -> 1.0.1)
# and creates a release
# Only increment patch version for non-major versions
- name: Check existing tag
id: check_tag
run: |
current_version=$(node -p "require('./package.json').version")
if [[ "$current_version" =~ ^[0-9]+\.0\.0$ ]]; then
# Don't increment major versions (x.0.0)
echo "version=$current_version" >> $GITHUB_OUTPUT
echo "version_changed=false" >> $GITHUB_OUTPUT
elif git ls-remote --tags origin | grep -q "refs/tags/v$current_version"; then
# If tag exists and it's not a major version, increment patch
IFS='.' read -r major minor patch <<< "$current_version"
new_version="$major.$minor.$((patch + 1))"
echo "version=$new_version" >> $GITHUB_OUTPUT
echo "version_changed=true" >> $GITHUB_OUTPUT
# Update package.json with new version
sed -i "s/\"version\": \"$current_version\"/\"version\": \"$new_version\"/" package.json
# Update manifest.json with new version
sed -i "s/\"version\": \"$current_version\"/\"version\": \"$new_version\"/" public/manifest.json
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add package.json public/manifest.json
git commit -m "chore: bump version to $new_version [skip ci]"
git push
else
echo "version=$current_version" >> $GITHUB_OUTPUT
echo "version_changed=false" >> $GITHUB_OUTPUT
fi
- name: Create Release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: softprops/action-gh-release@v1
with:
name: Chrome Extension v${{ steps.check_tag.outputs.version }}
tag_name: v${{ steps.check_tag.outputs.version }}
files: extensions/chrome/chrome-extension.zip
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
fail_on_unmatched_files: true