diff --git a/.github/workflows/action-publish-schema.yml b/.github/workflows/action-publish-schema.yml index 4eb2a3827..57129c8c9 100644 --- a/.github/workflows/action-publish-schema.yml +++ b/.github/workflows/action-publish-schema.yml @@ -16,8 +16,42 @@ permissions: id-token: write jobs: + check-published-version: + runs-on: ubuntu-latest + outputs: + version-exists: ${{ steps.check-published-version.outputs.version-exists }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org/' + + - name: Fetch package name + id: fetch-package-name + run: echo "PACKAGE_NAME=$(jq -r '.name' package.json)" >> $GITHUB_ENV + working-directory: ${{ env.WORKING_DIRECTORY }} + + - name: Check if version exists on NPM + id: check-published-version + run: | + if npm view "${{ env.PACKAGE_NAME }}@${{ inputs.version }}" > /dev/null 2>&1; then + echo "version-exists=true" >> $GITHUB_OUTPUT + echo "Version ${{ inputs.version }} already exists" + else + echo "version-exists=false" >> $GITHUB_OUTPUT + echo "Version ${{ inputs.version }} does not exist" + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + publish-schema-to-npm: runs-on: ubuntu-latest + needs: check-published-version + if: needs.check-published-version.outputs.version-exists == 'false' steps: - name: Checkout code uses: actions/checkout@v4