diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 56327a3..ee5dd08 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,42 +24,77 @@ env: jobs: + check-versions: + runs-on: ubuntu-latest + outputs: + do-release: ${{ steps.check-versions.outputs.do-release }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: https://registry.npmjs.org/ + + - name: Check Versions + id: check-versions + run: | + if [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then + echo "do-release='true'" >> $GITHUB_OUTPUT + exit 0 + fi + + local_version=$(npm pkg get version | tr -d '"')" + npm_version=$(npm show $GITHUB_REPOSITORY version) + + npm install -g semver + + if semver -r ">${npm_version}" "${local_version}"; then + echo "Local version is greater than npm version: run release" + echo "do-release='true'" >> $GITHUB_OUTPUT + else + echo "Local version is not greater than npm version: nothing to do." + echo "do-release='false'" >> $GITHUB_OUTPUT + fi + publish-npm: runs-on: ubuntu-latest + needs: check-versions + if: ${{ needs.check-versions.outputs.do-release == 'true' }} environment: npm steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: 22 - registry-url: https://registry.npmjs.org/ - - - name: Run Unit Tests - if: ${{ github.event.inputs.dry-run == 'false' }} - run: | - npm ci - npm run test - - - name: Publish to npm - run: npm publish --access public $DRY_RUN_OPTION - env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} - - - name: Get Version - id: get-version - run: | - echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT - - - name: Parse CHANGELOG.md - id: parse-changelog - uses: schwma/parse-changelog-action@v1.0.0 - with: - version: '${{ steps.get-version.outputs.version }}' - - - name: Create a GitHub release - if: ${{ github.event.inputs.dry-run == 'false' }} - uses: ncipollo/release-action@v1 - with: - tag: 'v${{ steps.get-version.outputs.version }}' - body: '${{ steps.parse-changelog.outputs.body }}' + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: https://registry.npmjs.org/ + + - name: Run Unit Tests + if: ${{ github.event.inputs.dry-run == 'false' }} + run: | + npm ci + npm run test + + - name: Publish to npm + run: npm publish --access public $DRY_RUN_OPTION + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} + + - name: Get Version + id: get-version + run: | + echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT + + - name: Parse CHANGELOG.md + id: parse-changelog + uses: schwma/parse-changelog-action@v1.0.0 + with: + version: '${{ steps.get-version.outputs.version }}' + + - name: Create a GitHub release + if: ${{ github.event.inputs.dry-run == 'false' }} + uses: ncipollo/release-action@v1 + with: + tag: 'v${{ steps.get-version.outputs.version }}' + body: '${{ steps.parse-changelog.outputs.body }}'