Skip to content

Commit

Permalink
ci: prevent schema from trying to publish existing version (#951)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

- Publishing the same version will fail. If we for example retry the
workflow for staging which will use the same tag

<!--- Describe your changes in detail -->

## 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)
  • Loading branch information
arealmaas authored Jul 31, 2024
1 parent 061046a commit 22d00d0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/action-publish-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22d00d0

Please sign in to comment.