diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 63e2b43..6724e44 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,63 +1,35 @@ name: Publish on: - push: - branches: [main] - paths: - - 'package.json' + release: + types: [published] jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Check if version changed - id: version_changed - run: | - # Check if this commit changed the version in package.json - if git diff HEAD~1 HEAD --name-only | grep -q "package.json"; then - CURRENT_VERSION=$(node -p "require('./package.json').version") - git checkout HEAD~1 -- package.json 2>/dev/null || echo "No previous version" - PREVIOUS_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0") - git checkout HEAD -- package.json - - echo "Current: $CURRENT_VERSION, Previous: $PREVIOUS_VERSION" - if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then - echo "version_bumped=true" >> $GITHUB_OUTPUT - else - echo "version_bumped=false" >> $GITHUB_OUTPUT - fi - else - echo "version_bumped=false" >> $GITHUB_OUTPUT - fi - - name: Setup Node.js - if: steps.version_changed.outputs.version_bumped == 'true' uses: actions/setup-node@v4 with: node-version: '20.x' - name: Create .npmrc file - if: steps.version_changed.outputs.version_bumped == 'true' run: | echo "//registry.npmjs.org/:_authToken=\${NPM_AUTH_TOKEN}" > .npmrc echo "registry=https://registry.npmjs.org/" >> .npmrc - name: Install dependencies - if: steps.version_changed.outputs.version_bumped == 'true' run: npm ci env: NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} - name: Run tests - if: steps.version_changed.outputs.version_bumped == 'true' run: npm test - name: Build - if: steps.version_changed.outputs.version_bumped == 'true' run: npm run build - name: Publish to npm - if: steps.version_changed.outputs.version_bumped == 'true' run: npm publish --access public env: NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 596b228..4c160d6 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -13,29 +13,46 @@ on: jobs: bump-version: runs-on: ubuntu-latest - permissions: + permissions: contents: write pull-requests: write steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - + token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20.x' - + - name: Configure Git run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - + - name: Bump version run: npm version ${{ github.event.inputs.bump_type }} -m "Bump version to %s" - + + - name: Get new version + id: get_version + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + - name: Push changes run: | git push - git push --tags \ No newline at end of file + git push --tags + + - name: Create GitHub Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.get_version.outputs.version }} + release_name: Release v${{ steps.get_version.outputs.version }} + body: | + Changes in this Release + - Auto-generated release for version ${{ steps.get_version.outputs.version }} + draft: false + prerelease: false \ No newline at end of file