From 22d00d08ffe323ba04102723b4113d3f4cff3c3f Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 31 Jul 2024 13:54:39 +0200 Subject: [PATCH] ci: prevent schema from trying to publish existing version (#951) ## Description - Publishing the same version will fail. If we for example retry the workflow for staging which will use the same tag ## Related Issue(s) - #{issue number} ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) --- .github/workflows/action-publish-schema.yml | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) 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