refactor: plugin #17
Workflow file for this run
This file contains hidden or 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 Marp Plugin | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ['v*'] | |
| pull_request: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain (wasm32-wasip1) | |
| uses: dtolnay/rust-toolchain@v1 | |
| with: | |
| toolchain: stable | |
| targets: wasm32-wasip1 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Determine plugin metadata | |
| run: | | |
| set -eux | |
| PLUGIN_ID=$(jq -r '.id' plugin.json) | |
| PLUGIN_VERSION=$(jq -r '.version' plugin.json) | |
| echo "PLUGIN_ID=$PLUGIN_ID" >> "$GITHUB_ENV" | |
| echo "PLUGIN_VERSION=$PLUGIN_VERSION" >> "$GITHUB_ENV" | |
| echo "PLUGIN_ZIP=${PLUGIN_ID}-plugin.zip" >> "$GITHUB_ENV" | |
| - name: Install frontend deps | |
| run: npm ci || npm i --no-audit --no-fund | |
| working-directory: frontend | |
| - name: Build frontend bundle | |
| run: npm run build | |
| working-directory: frontend | |
| - name: Build backend wasm | |
| run: cargo build --release --target wasm32-wasip1 | |
| working-directory: backend | |
| - name: Package plugin assets | |
| run: | | |
| set -eux | |
| DIST=dist | |
| rm -rf "$DIST" | |
| mkdir -p "$DIST/backend" | |
| WASM=$(find backend/target/wasm32-wasip1/release -maxdepth 1 -name '*.wasm' | head -n1) | |
| cp "$WASM" "$DIST/backend/plugin.wasm" | |
| cp frontend/dist/index.mjs "$DIST/index.mjs" | |
| cp plugin.json "$DIST/plugin.json" | |
| cp README.md "$DIST/README.md" | |
| (cd "$DIST" && zip -r "../${PLUGIN_ZIP}" .) | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.PLUGIN_ID }}-plugin | |
| path: ${{ env.PLUGIN_ZIP }} | |
| - name: Create release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| release_name: ${{ github.ref_name }} | |
| draft: false | |
| prerelease: false | |
| - name: Upload release asset | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ${{ env.PLUGIN_ZIP }} | |
| asset_name: ${{ env.PLUGIN_ZIP }} | |
| asset_content_type: application/zip |