|
@@ -0,0 +1,151 @@
|
|
|
+name: Build Release Assets
|
|
|
+
|
|
|
+on:
|
|
|
+ release:
|
|
|
+ types: [created]
|
|
|
+
|
|
|
+jobs:
|
|
|
+ security-check:
|
|
|
+ runs-on: ubuntu-latest
|
|
|
+ steps:
|
|
|
+ - name: Check release creator
|
|
|
+ run: |
|
|
|
+ CREATOR="${{ github.event.release.author.login }}"
|
|
|
+ ALLOWED_USERS="${{ vars.ALLOWED_RELEASE_USERS }}"
|
|
|
+
|
|
|
+ # More precise check using array
|
|
|
+ IFS=' ' read -ra USERS <<< "$ALLOWED_USERS"
|
|
|
+ AUTHORIZED=false
|
|
|
+ for user in "${USERS[@]}"; do
|
|
|
+ if [ "$user" = "$CREATOR" ]; then
|
|
|
+ AUTHORIZED=true
|
|
|
+ break
|
|
|
+ fi
|
|
|
+ done
|
|
|
+
|
|
|
+ if [ "$AUTHORIZED" = false ]; then
|
|
|
+ echo "Release created by unauthorized user: $CREATOR"
|
|
|
+ echo "Allowed users: $ALLOWED_USERS"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ echo "Release creator authorized: $CREATOR"
|
|
|
+
|
|
|
+ build-assets:
|
|
|
+ needs: security-check
|
|
|
+ runs-on: ubuntu-latest
|
|
|
+ environment: production
|
|
|
+ steps:
|
|
|
+ - name: Checkout code
|
|
|
+ uses: actions/checkout@v4
|
|
|
+ with:
|
|
|
+ fetch-depth: 1
|
|
|
+
|
|
|
+ - name: Setup Node.js
|
|
|
+ uses: actions/setup-node@v4
|
|
|
+ with:
|
|
|
+ node-version: '22'
|
|
|
+
|
|
|
+ - name: Setup pnpm
|
|
|
+ uses: pnpm/action-setup@v3
|
|
|
+ with:
|
|
|
+ version: 9.15.1
|
|
|
+
|
|
|
+ - name: Get pnpm store directory
|
|
|
+ id: pnpm-cache
|
|
|
+ shell: bash
|
|
|
+ run: |
|
|
|
+ echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
|
|
|
+
|
|
|
+ - name: Setup pnpm cache
|
|
|
+ uses: actions/cache@v3
|
|
|
+ with:
|
|
|
+ path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
|
|
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
|
+ restore-keys: |
|
|
|
+ ${{ runner.os }}-pnpm-store-
|
|
|
+
|
|
|
+ - name: Extract version from tag
|
|
|
+ id: get_version
|
|
|
+ run: |
|
|
|
+ # Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
|
|
|
+ VERSION=${GITHUB_REF_NAME#v}
|
|
|
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
|
|
|
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
|
+ echo "Extracted version: $VERSION"
|
|
|
+
|
|
|
+ - name: Create Source Code Archives
|
|
|
+ run: |
|
|
|
+ # Create a temporary directory for the source code
|
|
|
+ mkdir -p temp_source
|
|
|
+
|
|
|
+ echo "Copying source files respecting .gitignore..."
|
|
|
+ # Copy all files respecting .gitignore
|
|
|
+ git ls-files | xargs -I {} cp --parents {} temp_source/
|
|
|
+
|
|
|
+ # Create archives with version in filename
|
|
|
+ cd temp_source
|
|
|
+ echo "Creating ZIP archive..."
|
|
|
+ zip -r ../nanobrowser-source-v$VERSION.zip .
|
|
|
+ echo "Creating TAR.GZ archive..."
|
|
|
+ tar -czf ../nanobrowser-source-v$VERSION.tar.gz .
|
|
|
+ cd ..
|
|
|
+
|
|
|
+ # Verify archives were created
|
|
|
+ if [ ! -f "nanobrowser-source-v$VERSION.zip" ] || [ ! -f "nanobrowser-source-v$VERSION.tar.gz" ]; then
|
|
|
+ echo "Error: Failed to create source archives"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ echo "Source archives created successfully"
|
|
|
+ ls -la nanobrowser-source-v$VERSION.*
|
|
|
+
|
|
|
+ # Clean up
|
|
|
+ rm -rf temp_source
|
|
|
+
|
|
|
+ - name: Build Chrome Extension
|
|
|
+ run: |
|
|
|
+ # Set version in package.json
|
|
|
+ echo "Setting version $VERSION in package.json"
|
|
|
+ jq ".version = \"$VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json
|
|
|
+
|
|
|
+ # Install dependencies
|
|
|
+ echo "Running pnpm clean..."
|
|
|
+ pnpm clean || { echo "Error during pnpm clean"; exit 1; }
|
|
|
+
|
|
|
+ echo "Installing dependencies..."
|
|
|
+ pnpm install || { echo "Error during pnpm install"; exit 1; }
|
|
|
+
|
|
|
+ # Build the extension
|
|
|
+ echo "Building extension..."
|
|
|
+ pnpm build || { echo "Error during pnpm build"; exit 1; }
|
|
|
+
|
|
|
+ # Rename dist folder to nanobrowser
|
|
|
+ echo "Renaming dist folder to nanobrowser..."
|
|
|
+ mv dist nanobrowser
|
|
|
+
|
|
|
+ # Create zip file
|
|
|
+ echo "Creating nanobrowser.zip..."
|
|
|
+ zip -r nanobrowser.zip nanobrowser
|
|
|
+
|
|
|
+ # Verify zip was created
|
|
|
+ if [ ! -f "nanobrowser.zip" ]; then
|
|
|
+ echo "Error: Failed to create nanobrowser.zip"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ echo "Chrome extension package created successfully"
|
|
|
+ ls -la nanobrowser.zip
|
|
|
+
|
|
|
+ # Delete the folder
|
|
|
+ rm -rf nanobrowser
|
|
|
+
|
|
|
+ - name: Upload Release Assets
|
|
|
+ uses: softprops/action-gh-release@v1
|
|
|
+ with:
|
|
|
+ files: |
|
|
|
+ nanobrowser-source-v${{ env.VERSION }}.zip
|
|
|
+ nanobrowser-source-v${{ env.VERSION }}.tar.gz
|
|
|
+ nanobrowser.zip
|
|
|
+ env:
|
|
|
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|