|
| 1 | +name: Build Comments Plugin |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ['v*'] |
| 7 | + pull_request: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Install Rust toolchain (wasm32-wasip1) |
| 22 | + uses: dtolnay/rust-toolchain@v1 |
| 23 | + with: |
| 24 | + toolchain: stable |
| 25 | + targets: wasm32-wasip1 |
| 26 | + |
| 27 | + - name: Set up Node.js |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: 20 |
| 31 | + |
| 32 | + - name: Determine plugin metadata |
| 33 | + run: | |
| 34 | + set -eux |
| 35 | + PLUGIN_ID=$(jq -r '.id' plugin.json) |
| 36 | + PLUGIN_VERSION=$(jq -r '.version' plugin.json) |
| 37 | + echo "PLUGIN_ID=$PLUGIN_ID" >> "$GITHUB_ENV" |
| 38 | + echo "PLUGIN_VERSION=$PLUGIN_VERSION" >> "$GITHUB_ENV" |
| 39 | + echo "PLUGIN_ZIP=${PLUGIN_ID}-plugin.zip" >> "$GITHUB_ENV" |
| 40 | +
|
| 41 | + - name: Install frontend deps |
| 42 | + run: npm ci || npm i --no-audit --no-fund |
| 43 | + working-directory: frontend |
| 44 | + |
| 45 | + - name: Build frontend bundle |
| 46 | + run: npm run build |
| 47 | + working-directory: frontend |
| 48 | + |
| 49 | + - name: Build backend wasm |
| 50 | + run: cargo build --release --target wasm32-wasip1 |
| 51 | + working-directory: backend |
| 52 | + |
| 53 | + - name: Package plugin assets |
| 54 | + run: | |
| 55 | + set -eux |
| 56 | + DIST=dist |
| 57 | + rm -rf "$DIST" |
| 58 | + mkdir -p "$DIST/backend" |
| 59 | + WASM="backend/target/wasm32-wasip1/release/${PLUGIN_ID}_plugin_backend.wasm" |
| 60 | + cp "$WASM" "$DIST/backend/plugin.wasm" |
| 61 | + cp frontend/dist/index.mjs "$DIST/index.mjs" |
| 62 | + cp plugin.json "$DIST/plugin.json" |
| 63 | + (cd "$DIST" && zip -r "../${PLUGIN_ZIP}" .) |
| 64 | +
|
| 65 | + - name: Upload artifact |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: ${{ env.PLUGIN_ID }}-plugin |
| 69 | + path: ${{ env.PLUGIN_ZIP }} |
| 70 | + |
| 71 | + - name: Create release |
| 72 | + if: startsWith(github.ref, 'refs/tags/') |
| 73 | + id: create_release |
| 74 | + uses: actions/create-release@v1 |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + with: |
| 78 | + tag_name: ${{ github.ref_name }} |
| 79 | + release_name: ${{ github.ref_name }} |
| 80 | + draft: false |
| 81 | + prerelease: false |
| 82 | + |
| 83 | + - name: Upload release asset |
| 84 | + if: startsWith(github.ref, 'refs/tags/') |
| 85 | + uses: actions/upload-release-asset@v1 |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + with: |
| 89 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 90 | + asset_path: ${{ env.PLUGIN_ZIP }} |
| 91 | + asset_name: ${{ env.PLUGIN_ZIP }} |
| 92 | + asset_content_type: application/zip |
0 commit comments