name: Maketplace plugin build on: pull_request_target: types: [labeled, unlabeled, closed] workflow_dispatch: env: PR_NUMBER: ${{ github.event.number }} BRANCH_NAME: ${{ github.head_ref || github.ref_name }} jobs: deploy-marketplace-plugin: if: ${{ github.event.action == 'labeled' && github.event.label.name == 'deploy-marketplace-plugin' }} runs-on: ubuntu-latest steps: - name: Sync repo uses: actions/checkout@v3 - name: Check if PR is from the same repo id: check_repo run: echo "::set-output name=is_fork::$(if [[ '${{ github.event.pull_request.head.repo.full_name }}' != '${{ github.event.pull_request.base.repo.full_name }}' ]]; then echo true; else echo false; fi)" - name: Fetch the remote branch if it's a forked PR if: steps.check_repo.outputs.is_fork == 'true' run: | git fetch origin pull/${{ github.event.number }}/head:${{ env.BRANCH_NAME }} git checkout ${{ env.BRANCH_NAME }} - name: Checkout if: steps.check_repo.outputs.is_fork == 'false' uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.ref }} - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: 18.18.2 - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_MAR_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_MAR_ACCESS_KEY }} aws-region: us-east-2 - name: Install and build dependencies in order run: | cd marketplace echo "šŸ”§ Installing all workspace dependencies" npm install echo "šŸ—ļø Building 'common' plugin first" npm run build --workspace=plugins/common || exit 1 echo "šŸ” Building all remaining plugins" PLUGINS=$(ls plugins | grep -v '^common$') for plugin in $PLUGINS; do echo "šŸ”Ø Building plugin: $plugin" npm run build --workspace=plugins/$plugin || exit 1 done - name: Build marketplace plugins and capture summary run: | cd marketplace echo "šŸš€ Uploading to S3" AWS_BUCKET=tooljet-plugins-stage node scripts/upload-to-s3.js | tee upload_summary.log - name: Extract upload summary id: upload_summary run: | SUMMARY=$(awk '/UPLOAD SUMMARY/,0' marketplace/upload_summary.log) echo "UPLOAD_SUMMARY<> $GITHUB_ENV echo "$SUMMARY" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - name: Comment on success if: success() uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const runId = process.env.GITHUB_RUN_ID; const runUrl = `https://github.com/${{ github.repository }}/actions/runs/${runId}`; const summary = process.env.UPLOAD_SUMMARY; const body = `Marketplace Plugin added to stage bucket\n\nšŸ” [View Deployment Logs & Summary](${runUrl})\n\n\`\`\`\n${summary}\n\`\`\``; github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body }); - name: Label update on success if: success() uses: actions/github-script@v6 with: script: | try { await github.rest.issues.removeLabel({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, name: 'deploy-marketplace-plugin' }) } catch (e) { console.log(e) } await github.rest.issues.addLabels({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, labels: ['marketplace-plugin-deployed'] }) - name: Comment on failure if: failure() uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const runId = process.env.GITHUB_RUN_ID; const runUrl = `https://github.com/${{ github.repository }}/actions/runs/${runId}`; await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `āŒ Marketplace Plugin deployment failed.\n\nšŸ” [View Deployment Logs & Summary](${runUrl})` });