Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 8 additions & 42 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,13 @@ jobs:
with:
path: "dist"

check_version:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
container:
image: node:lts
needs:
- transpile
outputs:
version: ${{ steps.version_check.outputs.version }}
is_prerelease: ${{ steps.version_check.outputs.is_prerelease }}
npm_tag: ${{ steps.version_check.outputs.npm_tag }}
steps:
- uses: actions/checkout@v3.3.0
- name: Get version and determine if prerelease
id: version_check
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
if echo "$VERSION" | grep -qE '\-'; then
TAG=$(echo "$VERSION" | sed -E 's/.*-([a-zA-Z]+).*/\1/')
echo "is_prerelease=true" >> $GITHUB_OUTPUT
echo "npm_tag=$TAG" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
echo "npm_tag=latest" >> $GITHUB_OUTPUT
fi

publish_to_npm:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
container:
image: node:lts
needs:
- transpile
- check_version
env:
DIST_FOLDER: "/dist/artifact"
steps:
Expand All @@ -75,31 +47,25 @@ jobs:
- run: cp package.json $DIST_FOLDER
- run: cp README.md $DIST_FOLDER
- run: npm install
- name: Publish the library (regular release)
if: needs.check_version.outputs.is_prerelease == 'false'
run: npm publish $DIST_FOLDER --provenance
- name: Publish the library (prerelease)
if: needs.check_version.outputs.is_prerelease == 'true'
run: npm publish $DIST_FOLDER --tag ${{ needs.check_version.outputs.npm_tag }} --provenance
- name: Publish the library.
run: npm publish $DIST_FOLDER

create_release:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs:
- check_version
- publish_to_npm
steps:
- uses: actions/checkout@v3.3.0
- name: Get version from package.json
id: version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Create tag and release
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag v${{ needs.check_version.outputs.version }}
git push origin v${{ needs.check_version.outputs.version }}
if [ "${{ needs.check_version.outputs.is_prerelease }}" = "true" ]; then
gh release create v${{ needs.check_version.outputs.version }} --generate-notes --prerelease
else
gh release create v${{ needs.check_version.outputs.version }} --generate-notes
fi
git tag v${{ steps.version.outputs.version }}
git push origin v${{ steps.version.outputs.version }}
gh release create v${{ steps.version.outputs.version }} --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}