|
| 1 | +name: Publish package |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: created |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +jobs: |
| 11 | + Publish: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + id-token: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Setup Action |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Setup Node.js |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: "latest" |
| 28 | + registry-url: https://registry.npmjs.org/ |
| 29 | + |
| 30 | + - name: Setup PNPM |
| 31 | + uses: pnpm/action-setup@v4 |
| 32 | + |
| 33 | + - name: Check for changes |
| 34 | + id: changes |
| 35 | + run: | |
| 36 | + if git rev-parse --verify ${{ github.event.before }} > /dev/null 2>&1; then |
| 37 | + git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q '^src/' && echo "changed=true" >> $GITHUB_OUTPUT || echo "changed=false" >> $GITHUB_OUTPUT |
| 38 | + else |
| 39 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Install dependencies |
| 43 | + if: github.event_name == 'release' || (github.event_name == 'push' && steps.changes.outputs.changed == 'true') |
| 44 | + run: pnpm install --no-frozen-lockfile |
| 45 | + |
| 46 | + - name: Build |
| 47 | + if: github.event_name == 'release' || (github.event_name == 'push' && steps.changes.outputs.changed == 'true') |
| 48 | + run: node --run build |
| 49 | + |
| 50 | + - name: Generate dev version |
| 51 | + if: github.event_name == 'push' && steps.changes.outputs.changed == 'true' |
| 52 | + run: | |
| 53 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 54 | + DEV_VERSION="${CURRENT_VERSION}-dev.$(date +'%Y%m%d%H%M%S')" |
| 55 | + npm version "$DEV_VERSION" --no-git-tag-version |
| 56 | +
|
| 57 | + - name: Deprecate old dev versions |
| 58 | + if: github.event_name == 'push' && steps.changes.outputs.changed == 'true' |
| 59 | + run: | |
| 60 | + PACKAGE_NAME=$(node -p "require('./package.json').name") |
| 61 | + npm view "$PACKAGE_NAME" versions --json | jq -r '.[]' | grep -E 'dev\.[0-9]+' | while read -r old_version; do |
| 62 | + echo "Deprecating $PACKAGE_NAME@$old_version" |
| 63 | + npm deprecate "$PACKAGE_NAME@$old_version" "Deprecated - use latest dev version" || true |
| 64 | + done |
| 65 | + env: |
| 66 | + NODE_AUTH_TOKEN: ${{secrets.NODETOKEN}} |
| 67 | + |
| 68 | + - name: Deprecate dev versions on release |
| 69 | + if: github.event_name == 'release' |
| 70 | + run: | |
| 71 | + PACKAGE_NAME=$(node -p "require('./package.json').name") |
| 72 | + npm view "$PACKAGE_NAME" versions --json | jq -r '.[]' | grep -E 'dev\.[0-9]+' | while read -r old_version; do |
| 73 | + echo "Deprecating $PACKAGE_NAME@$old_version" |
| 74 | + npm deprecate "$PACKAGE_NAME@$old_version" "Deprecated - superseded by stable release" || true |
| 75 | + done |
| 76 | + env: |
| 77 | + NODE_AUTH_TOKEN: ${{secrets.NODETOKEN}} |
| 78 | + |
| 79 | + - name: Publish release |
| 80 | + if: github.event_name == 'release' |
| 81 | + run: pnpm publish --provenance --access public --no-git-checks |
| 82 | + env: |
| 83 | + NODE_AUTH_TOKEN: ${{secrets.NODETOKEN}} |
| 84 | + |
| 85 | + - name: Publish dev |
| 86 | + if: github.event_name == 'push' && steps.changes.outputs.changed == 'true' |
| 87 | + run: pnpm publish --provenance --access public --no-git-checks --tag dev |
| 88 | + env: |
| 89 | + NODE_AUTH_TOKEN: ${{secrets.NODETOKEN}} |
0 commit comments