1
- name : ipsimple.org - Build | Test | Deploy
1
+ name : ipsimple.org - CI/CD Pipeline
2
2
3
3
on :
4
4
push :
@@ -21,17 +21,69 @@ jobs:
21
21
- name : Install dependencies
22
22
run : npm install
23
23
24
- # - name: Run Linter
25
- # run: npm run lint
24
+ - name : Fetch and tag the release
25
+ id : tag_release
26
+ run : |
27
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
28
+ git config --global user.name "github-actions[bot]"
29
+
30
+ # Fetch tags from the remote repository
31
+ git fetch --tags || { echo "Failed to fetch tags"; exit 1; }
32
+
33
+ # Get the latest tag
34
+ LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "")
35
+
36
+ # If no tags are found, start from 1.0.0
37
+ if [ -z "$LATEST_TAG" ]; then
38
+ echo "No tags found. Starting from 1.0.0"
39
+ NEW_TAG="1.0.0"
40
+ else
41
+ echo "Latest tag found: $LATEST_TAG"
42
+ # Parse the latest version
43
+ VERSION_REGEX="^([0-9]+)\.([0-9]+)\.([0-9]+)$"
44
+ if [[ $LATEST_TAG =~ $VERSION_REGEX ]]; then
45
+ MAJOR="${BASH_REMATCH[1]}"
46
+ MINOR="${BASH_REMATCH[2]}"
47
+ PATCH="${BASH_REMATCH[3]}"
48
+
49
+ # Increment the minor version
50
+ MINOR=$((MINOR + 1))
51
+
52
+ # Reset minor and increment major if minor reaches 100
53
+ if [ $MINOR -eq 100 ]; then
54
+ MINOR=0
55
+ MAJOR=$((MAJOR + 1))
56
+ fi
57
+
58
+ # Form the new version tag
59
+ NEW_TAG="$MAJOR.$MINOR.$PATCH"
60
+ else
61
+ echo "Latest tag is not in the expected format: $LATEST_TAG"
62
+ exit 1
63
+ fi
64
+ fi
26
65
27
- - name : List build directory contents
28
- run : ls -la build
66
+ echo "Creating new tag: $NEW_TAG"
67
+ # Create and push the new tag
68
+ git tag $NEW_TAG || { echo "Failed to create tag $NEW_TAG"; exit 1; }
69
+ git push origin $NEW_TAG || { echo "Failed to push tag $NEW_TAG"; exit 1; }
70
+
71
+ # Set the new tag as an output variable
72
+ echo "::set-output name=new_tag::$NEW_TAG"
73
+
74
+ - name : Set version as environment variable
75
+ run : echo "NEW_TAG=${{ steps.tag_release.outputs.new_tag }}" >> $GITHUB_ENV
76
+
77
+ - name : Run Linter
78
+ run : npm run lint
29
79
30
80
- name : Build project
81
+ env :
82
+ NEW_TAG : ${{ steps.tag_release.outputs.new_tag }}
31
83
run : npm run build
32
-
84
+
33
85
- name : Run Tests
34
- run : npm test
86
+ run : npm test
35
87
36
88
- name : Deploy to GitHub Pages
37
89
uses : peaceiris/actions-gh-pages@v3
40
92
publish_dir : ./dist
41
93
publish_branch : main
42
94
43
- - name : Tag the release
44
- if : github.ref == 'refs/heads/dev'
45
- run : |
46
- git config --global user.email "github-actions[bot]@users.noreply.github.com"
47
- git config --global user.name "github-actions[bot]"
48
-
49
- # Fetch tags from the remote repository
50
- git fetch --tags || { echo "Failed to fetch tags"; exit 1; }
51
-
52
- # Get the latest tag
53
- LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "")
54
-
55
- # If no tags are found, start from 1.0.0
56
- if [ -z "$LATEST_TAG" ]; then
57
- echo "No tags found. Starting from 1.0.0"
58
- NEW_TAG="1.0.0"
59
- else
60
- echo "Latest tag found : $LATEST_TAG"
61
- # Parse the latest version
62
- VERSION_REGEX="^([0-9]+)\.([0-9]+)\.([0-9]+)$"
63
- if [[ $LATEST_TAG =~ $VERSION_REGEX ]]; then
64
- MAJOR="${BASH_REMATCH[1]}"
65
- MINOR="${BASH_REMATCH[2]}"
66
- PATCH="${BASH_REMATCH[3]}"
67
-
68
- # Increment the minor version
69
- MINOR=$((MINOR + 1))
70
-
71
- # Reset minor and increment major if minor reaches 100
72
- if [ $MINOR -eq 100 ]; then
73
- MINOR=0
74
- MAJOR=$((MAJOR + 1))
75
- fi
76
-
77
- # Form the new version tag
78
- NEW_TAG="$MAJOR.$MINOR.$PATCH"
79
- else
80
- echo "Latest tag is not in the expected format : $LATEST_TAG"
81
- exit 1
82
- fi
83
- fi
84
-
85
- echo "Creating new tag : $NEW_TAG"
86
- # Create and push the new tag
87
- git tag $NEW_TAG || { echo "Failed to create tag $NEW_TAG"; exit 1; }
88
- git push origin $NEW_TAG || { echo "Failed to push tag $NEW_TAG"; exit 1; }
89
-
90
- # Set the new tag as an environment variable
91
- echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
92
-
93
-
94
95
- name : Comment on the commit
95
96
uses : actions/github-script@v3
96
97
with :
@@ -106,4 +107,3 @@ jobs:
106
107
body: `Deployment successful with release ${newTag}!`
107
108
};
108
109
await github.repos.createCommitComment(comment);
109
-
0 commit comments