@logickernel/agileflow 0.4.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,9 +80,9 @@ jobs:
80
80
  **GitLab CI** (`.gitlab-ci.yml`):
81
81
  ```yaml
82
82
  agileflow:
83
- stage: version
84
- image: node:20-alpine
83
+ image: node:20
85
84
  script:
85
+ - npm install -g @logickernel/agileflow
86
86
  - npx @logickernel/agileflow gitlab
87
87
  rules:
88
88
  - if: '$CI_COMMIT_BRANCH == "main"'
@@ -121,9 +121,9 @@ jobs:
121
121
  ```yaml
122
122
  # Runs on merge to main - creates the tag
123
123
  agileflow:
124
- stage: version
125
- image: node:20-alpine
124
+ image: node:20
126
125
  script:
126
+ - npm install -g @logickernel/agileflow
127
127
  - npx @logickernel/agileflow gitlab
128
128
  rules:
129
129
  - if: '$CI_COMMIT_BRANCH == "main"'
@@ -189,8 +189,9 @@ stages:
189
189
  # Versioning job - runs on merge to main
190
190
  agileflow:
191
191
  stage: version
192
- image: node:20-alpine
192
+ image: node:20
193
193
  script:
194
+ - npm install @logickernel/agileflow
194
195
  - npx @logickernel/agileflow gitlab
195
196
  rules:
196
197
  - if: '$CI_COMMIT_BRANCH == "main"'
@@ -199,9 +200,7 @@ agileflow:
199
200
  build:
200
201
  stage: build
201
202
  script:
202
- - echo "Building version $CI_COMMIT_TAG"
203
- - docker build -t myapp:$CI_COMMIT_TAG .
204
- - docker push myapp:$CI_COMMIT_TAG
203
+ # Script to build your software, usually a docker image that is pulled to a registry
205
204
  rules:
206
205
  - if: '$CI_COMMIT_TAG =~ /^v/'
207
206
 
@@ -209,7 +208,7 @@ build:
209
208
  deploy-staging:
210
209
  stage: deploy
211
210
  script:
212
- - kubectl set image deployment/myapp myapp=myapp:$CI_COMMIT_TAG
211
+ # Script to deploy your software in staging
213
212
  environment:
214
213
  name: staging
215
214
  rules:
@@ -218,7 +217,7 @@ deploy-staging:
218
217
  deploy-production:
219
218
  stage: deploy
220
219
  script:
221
- - kubectl set image deployment/myapp myapp=myapp:$CI_COMMIT_TAG
220
+ # Script to deploy your software in production
222
221
  environment:
223
222
  name: production
224
223
  rules:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logickernel/agileflow",
3
- "version": "0.4.1",
3
+ "version": "0.12.0",
4
4
  "description": "Automatic semantic versioning and changelog generation based on conventional commits",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -91,7 +91,7 @@ function createTagViaAPI(tagName, message, projectPath, serverHost, accessToken,
91
91
  * @param {string} message - The tag message
92
92
  * @returns {Promise<void>}
93
93
  */
94
- async function pushTag(tagName, message) {
94
+ async function pushTag(tagName, message, quiet = false) {
95
95
  const accessToken = process.env.AGILEFLOW_TOKEN;
96
96
  const serverHost = process.env.CI_SERVER_HOST;
97
97
  const projectPath = process.env.CI_PROJECT_PATH;
@@ -128,6 +128,11 @@ async function pushTag(tagName, message) {
128
128
  }
129
129
 
130
130
  await createTagViaAPI(tagName, message || tagName, projectPath, serverHost, accessToken, commitSha);
131
+
132
+ if (!quiet) {
133
+ const commitUrl = `https://${process.env.CI_SERVER_HOST}/${process.env.CI_PROJECT_PATH}/-/commit/${process.env.CI_COMMIT_SHA}/pipelines`;
134
+ console.log(`Tag ${tagName} created and pushed successfully.\nView the build pipelines at: ${commitUrl}`);
135
+ }
131
136
  }
132
137
 
133
138
  module.exports = {
package/src/utils.js CHANGED
@@ -52,18 +52,27 @@ function ensureGitRepo() {
52
52
  /**
53
53
  * Gets the current branch name.
54
54
  * @returns {string} Current branch name
55
- * @throws {Error} If in detached HEAD state
55
+ * @throws {Error} If in detached HEAD state and no CI environment variable is available
56
56
  */
57
57
  function getCurrentBranch() {
58
58
  const branch = runWithOutput('git branch --show-current').trim();
59
- if (!branch) {
60
- throw new Error('Repository is in a detached HEAD state. Please check out a branch and try again.');
59
+ if (branch) {
60
+ return branch;
61
61
  }
62
- return branch;
62
+
63
+ // Handle detached HEAD state (common in CI environments)
64
+ // GitLab CI provides CI_COMMIT_BRANCH (for branches) or CI_COMMIT_REF_NAME (for branches/tags)
65
+ // GitHub Actions provides GITHUB_REF_NAME (for branches/tags)
66
+ const ciBranch = process.env.CI_COMMIT_BRANCH || process.env.CI_COMMIT_REF_NAME || process.env.GITHUB_REF_NAME;
67
+ if (ciBranch) {
68
+ return ciBranch;
69
+ }
70
+
71
+ throw new Error('Repository is in a detached HEAD state. Please check out a branch and try again.');
63
72
  }
64
73
 
65
74
  // Conventional commit type configuration
66
- const TYPE_ORDER = ['feat', 'fix', 'perf', 'refactor', 'style', 'test', 'docs', 'build', 'ci', 'chore', 'revert'];
75
+ const TYPE_ORDER = ['feat', 'fix', 'perf', 'refactor', 'style', 'test', 'build', 'ci', 'docs', 'chore', 'revert'];
67
76
  const PATCH_TYPES = ['fix', 'perf', 'refactor', 'test', 'build', 'ci', 'revert'];
68
77
  const SEMVER_PATTERN = /^v(\d+)\.(\d+)\.(\d+)(-[a-zA-Z0-9.-]+)?$/;
69
78
 
@@ -375,17 +384,25 @@ function calculateNextVersionAndChangelog(expandedInfo) {
375
384
  * @returns {Array<{hash: string, datetime: string, author: string, message: string, tags: Array<string>}>}
376
385
  */
377
386
  function getAllBranchCommits(branch) {
387
+ // Try to resolve the branch (may be a local branch or remote branch like origin/main)
388
+ let branchRef = branch;
378
389
  try {
379
390
  runWithOutput(`git rev-parse --verify ${branch}`);
380
391
  } catch {
381
- return [];
392
+ // Try with origin/ prefix (common in CI environments where local branch doesn't exist)
393
+ try {
394
+ runWithOutput(`git rev-parse --verify origin/${branch}`);
395
+ branchRef = `origin/${branch}`;
396
+ } catch {
397
+ return [];
398
+ }
382
399
  }
383
400
 
384
401
  const RS = '\x1E';
385
402
  const COMMIT_SEP = `${RS}${RS}`;
386
403
 
387
404
  try {
388
- const logCmd = `git log --format=%H${RS}%ai${RS}%an${RS}%B${COMMIT_SEP} ${branch}`;
405
+ const logCmd = `git log --format=%H${RS}%ai${RS}%an${RS}%B${COMMIT_SEP} ${branchRef}`;
389
406
  const output = runWithOutput(logCmd).trim();
390
407
  if (!output) return [];
391
408