final #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Conditional Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
release: | |
name: Release and Publish Package | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "lts/*" | |
- name: Install Dependencies | |
run: npm install | |
- name: Check for File Changes | |
id: file_changes | |
run: | | |
git fetch --depth=2 | |
# Check if HEAD~1 is available, else use HEAD | |
if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then | |
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD) | |
else | |
CHANGED_FILES=$(git diff --name-only HEAD) | |
fi | |
echo "Changed files: $CHANGED_FILES" | |
# Check if relevant files have changed | |
if ! echo "$CHANGED_FILES" | grep -qE "^(index.ts|api.ts)$"; then | |
echo "No relevant file changes detected. Skipping version bump and release." | |
exit 0 | |
fi | |
- name: Bump Version and Create Release | |
id: bump-version | |
run: | | |
git config --local user.name "GitHub Action" | |
git config --local user.email "[email protected]" | |
npm version patch -m "Release version %s" | |
git push origin main --follow-tags | |
echo "New version: $(npm pkg get version)" | |
- name: Publish to npm | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Create GitHub Release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: v${{ steps.bump-version.outputs.new_version }} | |
release_name: Release ${{ steps.bump-version.outputs.new_version }} | |
draft: false | |
prerelease: false | |
body: | | |
Release of version ${{ steps.bump-version.outputs.new_version }} |