diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0d7de7..4ec7a08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,8 @@ jobs: run: npm rebuild && npm run prepare --if-present - name: Test run: npm test + - name: Check release script + run: bash -n release.sh - name: Release if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} run: ./release.sh diff --git a/release.sh b/release.sh index 6166f39..3673a45 100755 --- a/release.sh +++ b/release.sh @@ -1,22 +1,20 @@ #!/bin/bash -VERSION=$(node -p "require('./package.json').version") - -git config --local user.email "github@reedsy.com" -git config --local user.name "GitHub Action" -git fetch --tags +set -eo pipefail -VERSION_COUNT=$(git tag --list $VERSION | wc -l) +PACKAGE=$(node -p "require('./package.json').name") +VERSION=$(node -p "require('./package.json').version") -if [ $VERSION_COUNT -gt 0 ] +if [ -n "$(npm view "$PACKAGE@$VERSION" version 2> /dev/null)" ] then - echo "Version $VERSION already deployed." + echo "Version $VERSION already published." exit 0 -else - echo "Deploying version $VERSION" fi -git tag $VERSION -git push origin refs/tags/$VERSION +echo "Publishing version $VERSION" +npm publish --tag latest -npm publish +if ! git tag "$VERSION" || ! git push origin "refs/tags/$VERSION" +then + echo "Published $VERSION but could not tag it." >&2 +fi