|
| 1 | +name: PR Tarball |
| 2 | +on: |
| 3 | + pull_request_target: |
| 4 | + branches: [main] |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + pull-requests: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + pr-tarball: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + if: >- |
| 14 | + contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.pull_request.author_association) |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v6 |
| 17 | + with: |
| 18 | + ref: ${{ github.event.pull_request.head.sha }} |
| 19 | + - uses: actions/setup-node@v6 |
| 20 | + with: |
| 21 | + node-version: '20.x' |
| 22 | + cache: 'npm' |
| 23 | + - name: Configure git |
| 24 | + run: | |
| 25 | + git config --global user.email "bedrock-agentcore-npm+ci@amazon.com" |
| 26 | + git config --global user.name "CI" |
| 27 | + - uses: astral-sh/setup-uv@v7 |
| 28 | + - run: npm ci |
| 29 | + - run: npm run build --if-present |
| 30 | + - run: npm pack |
| 31 | + - name: Get tarball info |
| 32 | + id: tarball |
| 33 | + run: | |
| 34 | + TARBALL_NAME=$(ls *.tgz | head -1 | xargs basename) |
| 35 | + echo "name=$TARBALL_NAME" >> $GITHUB_OUTPUT |
| 36 | + - name: Create or update PR release |
| 37 | + id: release |
| 38 | + env: |
| 39 | + GH_TOKEN: ${{ github.token }} |
| 40 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 41 | + TARBALL_NAME: ${{ steps.tarball.outputs.name }} |
| 42 | + run: | |
| 43 | + TAG="pr-${PR_NUMBER}-tarball" |
| 44 | +
|
| 45 | + # Delete existing release if it exists (to update the tarball) |
| 46 | + gh release delete "$TAG" --yes --cleanup-tag 2>/dev/null || true |
| 47 | +
|
| 48 | + # Create a new pre-release with the tarball |
| 49 | + gh release create "$TAG" \ |
| 50 | + "${TARBALL_NAME}" \ |
| 51 | + --title "PR #${PR_NUMBER} Tarball" \ |
| 52 | + --notes "Auto-generated tarball for PR #${PR_NUMBER}." \ |
| 53 | + --prerelease \ |
| 54 | + --target "${{ github.event.pull_request.head.sha }}" |
| 55 | +
|
| 56 | + DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}/${TARBALL_NAME}" |
| 57 | + echo "url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT |
| 58 | + - name: Comment on PR |
| 59 | + uses: marocchino/sticky-pull-request-comment@v3 |
| 60 | + with: |
| 61 | + header: tarball |
| 62 | + message: | |
| 63 | + ## Package Tarball |
| 64 | +
|
| 65 | + **[${{ steps.tarball.outputs.name }}](${{ steps.release.outputs.url }})** |
| 66 | +
|
| 67 | + ### How to install |
| 68 | +
|
| 69 | + ```bash |
| 70 | + npm install ${{ steps.release.outputs.url }} |
| 71 | + ``` |
0 commit comments