To create a GitHub Action that builds WebAssembly (WASM) files and releases them, we need to leverage the information from the Custom Demuxer section in README.md and the scripts in package.json. Here’s a step-by-step guide to create the action:
Key Details from the Repository
Custom Demuxer Section:
The build process for specific formats involves:
Modifying the Makefile (if needed) for custom configurations.
Running Docker-based scripts to build the WASM files.
npm run build:wasm:all builds both the full and minimalist versions of the WASM files.
Release Process:
Generated WASM and JS files are located in the dist/wasm-files/ directory.
The softprops/action-gh-release@v1 action can be used to upload release artifacts.
Docker Integration:
Docker containers (dev-web-demuxer-arm64 or dev-web-demuxer-x86_64) are used for building the WASM files. The docker-compose setup is defined in compose.yaml.
Relevant Scripts in package.json:
Build the WASM files: npm run build:wasm:all.
Build and release process: Files are packaged into dist/wasm-files/ which should be included in the release.
GitHub Action Workflow
Create a file .github/workflows/build-and-release-wasm.yml with the following content:
[Redacted
name: Build and Release WASM
on:
push:
tags:
- 'v*' # Trigger only on version tags
workflow_dispatch: # Allow manual trigger for debugging or custom builds
jobs:
build-and-release:
name: Build and Release WASM Files
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v4
# Step 2: Set up Node.js environment
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18' # Required version from package.json
cache: 'npm'
# Step 3: Install dependencies
- name: Install Dependencies
run: npm ci
# Step 4: Install Docker for building WASM files
- name: Install Docker
run: |
sudo apt-get update
sudo apt-get install -y docker.io
# Step 5: Install Docker Compose
- name: Install Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Step 6: Start Docker environment for WebAssembly build
- name: Start Docker Environment
run: docker-compose up dev-web-demuxer-x86_64 -d
# Step 7: Build the WASM files
- name: Build WASM Files
run: npm run build:wasm:all
# Step 8: Verify Built Files
- name: Verify Built Files
run: ls -lh dist/wasm-files
# Step 9: Upload Release Assets
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
files: |
dist/wasm-files/ffmpeg.wasm
dist/wasm-files/ffmpeg.min.js
dist/wasm-files/ffmpeg-mini.wasm
dist/wasm-files/ffmpeg-mini.min.js
dist/web-demuxer.js
dist/web-demuxer.umd.cjs
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Explanation of Workflow Steps
Trigger Conditions:
The workflow is triggered on a push event for version tags (e.g., v1.0.0) or manually via the workflow_dispatch event.
Setup Steps:
The repository is checked out using the actions/checkout action.
Node.js is set up to use version 18, as specified in package.json.
Dependencies:
The npm ci command ensures a clean and consistent installation of dependencies.
Docker Installation:
Docker and Docker Compose are installed to support the build process since the WASM build depends on Docker containers.
Build Process:
The Docker Compose service dev-web-demuxer-x86_64 is started, and the WASM build is initiated using npm run build:wasm:all.
Release Step:
The built files in the dist/wasm-files/ directory are uploaded as release assets using the softprops/action-gh-release action.
Notes
Custom Configuration:
If you need to use a custom demuxer configuration, update the Makefile as described in the README, or pass relevant build arguments before executing npm run build:wasm:all.
Docker Configuration:
The docker-compose file already supports both arm64 and x86_64 architectures. Adjust the service in Step 6 (docker-compose up) if you need to target a different architecture.
Security:
Ensure that the GITHUB_TOKEN secret is available for the release step.
Example Release Output
When the workflow completes, the following files will be attached to the GitHub release:
dist/wasm-files/ffmpeg.wasm
dist/wasm-files/ffmpeg.min.js
dist/wasm-files/ffmpeg-mini.wasm
dist/wasm-files/ffmpeg-mini.min.js
dist/web-demuxer.js
dist/web-demuxer.umd.cjs
These files can then be downloaded and used by the end-users.
This workflow automates the process of building and releasing the WASM files, ensuring consistency and efficiency.