fix build #8
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 - Build | Test | Deploy | |
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: List build directory contents | |
run: ls -la build | |
- name: Build project | |
run: npm run build | |
- name: Run Tests | |
run: npm test | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./dist | |
publish_branch: main | |
- name: Tag the release | |
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 || { echo "Failed to fetch tags"; exit 1; } | |
# Get the latest tag | |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "") | |
# If no tags are found, start from 1.0.0 | |
if [ -z "$LATEST_TAG" ]; then | |
echo "No tags found. Starting from 1.0.0" | |
NEW_TAG="1.0.0" | |
else | |
echo "Latest tag found: $LATEST_TAG" | |
# 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 | |
echo "Creating new tag: $NEW_TAG" | |
# Create and push the new tag | |
git tag $NEW_TAG || { echo "Failed to create tag $NEW_TAG"; exit 1; } | |
git push origin $NEW_TAG || { echo "Failed to push tag $NEW_TAG"; exit 1; } | |
# Set the new tag as an environment variable | |
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV | |
- 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); | |