Update ci.yml #92
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: CI | |
| on: | |
| - push | |
| - pull_request | |
| - workflow_dispatch | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| submodule-matrix: ${{ steps.discover-submodules.outputs.submodule-matrix }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| with: | |
| submodules: recursive | |
| persist-credentials: true | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: '20' | |
| - name: Install pnpm | |
| run: npm install -g pnpm | |
| - name: Discover submodules | |
| id: discover-submodules | |
| run: | | |
| sudo node ./scripts/discover-submodules.js > submodules.json | |
| echo "Original Submodule JSON content:" | |
| cat submodules.json | |
| # Transform JSON into a list of 'owner/repo' strings | |
| jq -c '[.[] | "\(.owner)/\(.repo)"]' submodules.json > transformed-submodules.json | |
| echo "Transformed Submodule JSON content:" | |
| cat transformed-submodules.json | |
| # Set the output for the submodule matrix | |
| echo "::set-output name=submodule-matrix::$(cat transformed-submodules.json)" | |
| process-plugin: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| repository: ${{ fromJson(needs.build.outputs.submodule-matrix) }} | |
| steps: | |
| - name: Checkout specific submodule repository | |
| uses: actions/checkout@v2 | |
| with: | |
| repository: ${{ matrix.repository }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: '20' | |
| - name: Install pnpm | |
| run: npm install -g pnpm | |
| - name: Install dependencies and build plugin | |
| run: | | |
| ls -R | |
| pnpm install | |
| pnpm run build | |
| env: | |
| NODE_ENV: production | |
| - name: Copy files to dist | |
| id: copy-files-to-dist | |
| run: | | |
| ls -R | |
| mkdir -p dist | |
| cp "plugin.json" dist/plugin.json 2>/dev/null || { echo "::error::plugin.json was not found. It is required for plugins to have."; exit 1; } | |
| cp "requirements.txt" dist/requirements.txt 2>/dev/null || echo "::warning::requirements.txt not found, skipping." | |
| cp "README.md" dist/README.md 2>/dev/null || echo "::warning::README.md not found, skipping." | |
| cp "README" dist/README 2>/dev/null || echo "::warning::README not found, skipping." | |
| backend=$(jq -r '.backend' plugin.json) | |
| if [ "$backend" != "null" ]; then | |
| cp -r "$backend" ./dist/"$backend" | |
| fi | |
| include=$(jq -r '.include // [] | @sh' plugin.json) | |
| echo "::notice::Including additional files: $include" | |
| if [ "$include" != "''" ]; then | |
| for file in $include; do | |
| cp -r "$file" ./dist/"$file" | |
| done | |
| fi | |
| echo "::notice::Computing plugin metadata..." | |
| echo "{\"commit\": \"$(git rev-parse HEAD)\", \"id\": \"$(git rev-list --max-parents=0 HEAD)\"}" > dist/metadata.json | |
| id=$(jq -r '.id' dist/metadata.json) | |
| echo "::set-output name=id::$id" # Set the id as an output variable | |
| cd dist | |
| zip -r "$id.zip" . | |
| echo "::notice::Successfully built plugin." | |
| - name: Upload plugin | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.copy-files-to-dist.outputs.id }} # Correct reference here | |
| path: dist/${{ steps.copy-files-to-dist.outputs.id }}.zip | |
| download: | |
| runs-on: ubuntu-latest | |
| needs: process-plugin # Ensure this job runs after the "build" job | |
| if: ${{ always() }} | |
| steps: | |
| - name: Download assets from the previous job | |
| run: | | |
| # Fetch the run ID of the previous job using the GitHub API | |
| RUN_ID=$(curl -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/runs" \ | |
| | jq -r '.workflow_runs[0].id') | |
| # List the assets from the previous workflow run | |
| ASSETS=$(curl -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/runs/$RUN_ID/assets" \ | |
| | jq -r '.[].url') | |
| # Download each asset using curl | |
| for ASSET_URL in $ASSETS; do | |
| curl -L -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| -o "asset.zip" "$ASSET_URL" | |
| done |