|
| 1 | +name: release-test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dry_run: |
| 7 | + description: 'Dry run (skip actual npm publish)' |
| 8 | + required: false |
| 9 | + default: false |
| 10 | + type: boolean |
| 11 | + |
| 12 | +env: |
| 13 | + NX_BRANCH: ${{ github.event.number }} |
| 14 | + NX_RUN_GROUP: ${{ github.run_id }} |
| 15 | + NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }} |
| 16 | + |
| 17 | +jobs: |
| 18 | + # verify the actor is an org member, not just a contributor |
| 19 | + check_permissions: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Check org membership |
| 23 | + uses: actions/github-script@v7 |
| 24 | + with: |
| 25 | + script: | |
| 26 | + try { |
| 27 | + await github.rest.orgs.checkMembershipForUser({ |
| 28 | + org: context.repo.owner, |
| 29 | + username: context.actor, |
| 30 | + }); |
| 31 | + core.info(`✅ ${context.actor} is a member of ${context.repo.owner}`); |
| 32 | + } catch (e) { |
| 33 | + core.setFailed( |
| 34 | + `❌ ${context.actor} is not a member of the ${context.repo.owner} organization. Only org members can trigger test releases.` |
| 35 | + ); |
| 36 | + } |
| 37 | +
|
| 38 | + # install dependencies |
| 39 | + install: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: check_permissions |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v3 |
| 44 | + - uses: actions/cache@v3 |
| 45 | + id: cache |
| 46 | + with: |
| 47 | + path: node_modules |
| 48 | + key: node_modules-${{ hashFiles('**/package-lock.json') }} |
| 49 | + - run: npm ci |
| 50 | + if: steps.cache.outputs.cache-hit != 'true' |
| 51 | + |
| 52 | + # build ngx-bootstrap |
| 53 | + build: |
| 54 | + needs: install |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v3 |
| 58 | + - uses: actions/cache@v3 |
| 59 | + with: |
| 60 | + path: node_modules |
| 61 | + key: node_modules-${{ hashFiles('**/package-lock.json') }} |
| 62 | + - uses: actions/cache@v3 |
| 63 | + with: |
| 64 | + path: dist |
| 65 | + key: dist-${{ github.run_id }} |
| 66 | + - run: npx nx build ngx-bootstrap --configuration=production |
| 67 | + |
| 68 | + # publish to npm with "test" dist-tag |
| 69 | + npm_publish_test: |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: build |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v3 |
| 74 | + - uses: actions/cache@v3 |
| 75 | + with: |
| 76 | + path: node_modules |
| 77 | + key: node_modules-${{ hashFiles('**/package-lock.json') }} |
| 78 | + - uses: actions/cache@v3 |
| 79 | + with: |
| 80 | + path: dist |
| 81 | + key: dist-${{ github.run_id }} |
| 82 | + |
| 83 | + - name: Stamp test version |
| 84 | + run: | |
| 85 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 86 | + TIMESTAMP=$(date -u +%Y%m%d%H%M%S) |
| 87 | + TEST_VERSION="${CURRENT_VERSION}-test.${TIMESTAMP}.${GITHUB_RUN_NUMBER}" |
| 88 | + echo "Publishing test version: ${TEST_VERSION}" |
| 89 | + echo "TEST_VERSION=${TEST_VERSION}" >> $GITHUB_ENV |
| 90 | + node -e " |
| 91 | + const fs = require('fs'); |
| 92 | + const pkgPath = 'dist/ngx-bootstrap/package.json'; |
| 93 | + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); |
| 94 | + pkg.version = '${TEST_VERSION}'; |
| 95 | + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)); |
| 96 | + console.log('Updated dist package version to', pkg.version); |
| 97 | + " |
| 98 | +
|
| 99 | + - name: Publish to npm (test tag) |
| 100 | + if: ${{ !inputs.dry_run }} |
| 101 | + uses: JS-DevTools/npm-publish@v1 |
| 102 | + with: |
| 103 | + package: "dist/ngx-bootstrap/package.json" |
| 104 | + token: ${{ secrets.NPM_TOKEN }} |
| 105 | + tag: test |
| 106 | + |
| 107 | + - name: Dry run summary |
| 108 | + if: ${{ inputs.dry_run }} |
| 109 | + run: | |
| 110 | + echo "🏷️ DRY RUN — would have published:" |
| 111 | + echo " Version: ${{ env.TEST_VERSION }}" |
| 112 | + echo " Tag: test" |
| 113 | + echo " Package: dist/ngx-bootstrap/package.json" |
| 114 | + cat dist/ngx-bootstrap/package.json | head -5 |
0 commit comments