Update release.yml #23
Workflow file for this run
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: Release Workflow | |
on: | |
push: | |
branches: | |
- release | |
permissions: | |
contents: write | |
actions: write | |
jobs: | |
build: | |
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: '18' | |
- name: Install dependencies | |
run: npm install | |
- name: Build for production | |
run: npm run build --omit=dev | |
- name: Configure Git | |
run: | | |
git checkout release | |
git pull origin release | |
git config --global user.name 'GitHub Actions' | |
git config --global user.email 'actions@github.com' | |
- name: Ensure clean working directory | |
run: | | |
git status --porcelain | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "Working directory is not clean. Stashing changes..." | |
git stash -u | |
fi | |
- name: Bump version and tag release | |
run: | | |
# Bump the version | |
npm version patch --no-git-tag-version -m "Bump version to %s" | |
# # Check if the tag already exists | |
# if git rev-parse "v$VERSION" >/dev/null 2>&1; then | |
# echo "Tag v$VERSION already exists. Deleting it." | |
# git tag -d "v$VERSION" | |
# git push origin --delete "v$VERSION" | |
# fi | |
# Add the updated files to the staging area | |
git add package.json package-lock.json | |
# Commit the changes with a message | |
git commit -m "Bump version to $(node -p "require('./package.json').version")" | |
# Create a new tag for the release | |
VERSION=$(node -p "require('./package.json').version") | |
git tag -a "v$VERSION" -m "Release version $VERSION" | |
# Push the commit and the tag to the remote repository | |
git push origin HEAD:main | |
git push origin "v$VERSION" | |
- name: Clean up release branch | |
run: | | |
git push origin --delete origin/release |