Update webpack.yml #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release Extension | |
on: | |
push: | |
branches: [ "main" ] | |
tags: | |
- 'v*' | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
strategy: | |
matrix: | |
node-version: [18.x] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Build | |
run: | | |
npm install | |
npx webpack | |
npm run build | |
- name: Validate Extension Files | |
run: | | |
# Check required files exist | |
required_files=("manifest.json" "popup/index.html" "background/background.js" "assets/icons/icon16.png" "assets/icons/icon48.png" "assets/icons/icon128.png") | |
for file in "${required_files[@]}"; do | |
if [ ! -f "dist/$file" ]; then | |
echo "Error: Required file $file is missing" | |
exit 1 | |
fi | |
done | |
# Validate manifest.json | |
if ! jq empty dist/manifest.json; then | |
echo "Error: Invalid manifest.json" | |
exit 1 | |
fi | |
# Check manifest version matches tag | |
if [[ "${{ github.ref }}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+) ]]; then | |
version="${BASH_REMATCH[1]}" | |
manifest_version=$(jq -r .version dist/manifest.json) | |
if [ "$version" != "$manifest_version" ]; then | |
echo "Error: Tag version ($version) doesn't match manifest version ($manifest_version)" | |
exit 1 | |
fi | |
fi | |
# Check file sizes | |
max_size=$((1024 * 1024 * 5)) # 5MB | |
find dist -type f -exec du -b {} + | while read size file; do | |
if [ "$size" -gt "$max_size" ]; then | |
echo "Error: $file exceeds 5MB limit" | |
exit 1 | |
fi | |
done | |
- name: Create Extension ZIP | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
cd dist | |
zip -r ../extension.zip * | |
cd .. | |
- name: Create Release | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: extension.zip | |
generate_release_notes: true |