name: Auto Bump and Publish on: push: branches: - main workflow_dispatch: inputs: bump: description: Version bump type required: true default: patch type: choice options: - patch - minor - major permissions: contents: write id-token: write concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: false jobs: bump-and-publish: if: github.actor != 'github-actions[bot]' runs-on: ubuntu-latest steps: - name: Determine bump type id: bump_type run: echo "value=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.bump || 'patch' }}" >> "$GITHUB_OUTPUT" - name: Wait 5 minutes for more commits if: github.event_name != 'workflow_dispatch' run: sleep 300 - name: Checkout latest branch uses: actions/checkout@v4 with: ref: ${{ github.ref_name }} fetch-depth: 0 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "24" registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci - name: Sync version with npm registry id: sync run: | # npm 레지스트리에 이미 publish된 최신 버전을 확인하여 # 로컬 package.json과 불일치하면 동기화한다. # (이전 CI에서 publish 성공 후 commit이 실패한 경우 발생) LOCAL=$(node -p "require('./package.json').version") REMOTE=$(npm view damn-my-slow-skt version 2>/dev/null || echo "0.0.0") echo "local=$LOCAL remote=$REMOTE" if npx semver "$REMOTE" -r ">$LOCAL" > /dev/null 2>&1; then echo "⚠️ npm registry ($REMOTE) > local ($LOCAL). Syncing..." npm version "$REMOTE" --no-git-tag-version --allow-same-version fi - name: Bump version id: bump run: | npm version ${{ steps.bump_type.outputs.value }} --no-git-tag-version VERSION=$(node -p "require('./package.json').version") echo "version=$VERSION" >> "$GITHUB_OUTPUT" - name: Build run: npm run build - name: Commit and push version bump run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add package.json package-lock.json 2>/dev/null || true if git diff --cached --quiet; then echo "No changes to commit." else git commit -m "chore: auto bump ${{ steps.bump_type.outputs.value }} to v${{ steps.bump.outputs.version }}" git push origin HEAD:${{ github.ref_name }} fi - name: Publish to npm (Trusted Publishers OIDC) run: npm publish --provenance --access public - name: Tag and release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git tag "v${{ steps.bump.outputs.version }}" git push origin "v${{ steps.bump.outputs.version }}" gh release create "v${{ steps.bump.outputs.version }}" --generate-notes