udpated version number cosmetics #15
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: ipsimple.org - CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm install | |
- name: Run Linter | |
run: npm run lint | |
- name: Tag the release | |
id: tag_version | |
if: github.ref == 'refs/heads/dev' | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
# Fetch tags from the remote repository | |
git fetch --tags | |
# Get the latest tag | |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) | |
# If no tags are found, start from 1.0.0 | |
if [ -z "$LATEST_TAG" ]; then | |
NEW_TAG="1.0.0" | |
else | |
# Parse the latest version | |
VERSION_REGEX="^([0-9]+)\.([0-9]+)\.([0-9]+)$" | |
if [[ $LATEST_TAG =~ $VERSION_REGEX ]]; then | |
MAJOR="${BASH_REMATCH[1]}" | |
MINOR="${BASH_REMATCH[2]}" | |
PATCH="${BASH_REMATCH[3]}" | |
# Increment the minor version | |
MINOR=$((MINOR + 1)) | |
# Reset minor and increment major if minor reaches 100 | |
if [ $MINOR -eq 100 ]; then | |
MINOR=0 | |
MAJOR=$((MAJOR + 1)) | |
fi | |
# Form the new version tag | |
NEW_TAG="$MAJOR.$MINOR.$PATCH" | |
else | |
echo "Latest tag is not in the expected format: $LATEST_TAG" | |
exit 1 | |
fi | |
fi | |
# Create and push the new tag | |
git tag $NEW_TAG | |
git push origin $NEW_TAG | |
# Set the new tag as an environment variable | |
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV | |
- name: Build project | |
run: npm run build | |
env: | |
NEW_TAG: ${{ env.NEW_TAG }} | |
- name: Run Tests | |
run: npm test | |
env: | |
NEW_TAG: ${{ env.NEW_TAG }} | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./dist | |
publish_branch: main | |
- name: Comment on the commit | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { owner, repo } = context.repo; | |
const commit_sha = context.sha; | |
const newTag = process.env.NEW_TAG; | |
const comment = { | |
owner, | |
repo, | |
commit_sha, | |
body: `Deployment successful with release ${newTag}!` | |
}; | |
await github.repos.createCommitComment(comment); |