Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

open-pull-requests-limit: 10
labels:
- "dependencies"
- "npm"
rebase-strategy: "auto"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 5
labels:
- "dependencies"
- "github-actions"
rebase-strategy: "auto"
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: [ 'javascript', 'typescript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

Expand Down
80 changes: 79 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,89 @@ on:
release:
types: [created]

env:
retention_days: 3

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full git history for version calculation

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v4.1.0
with:
versionSpec: "6.3.x"

- name: Determine Version
id: version_step # step id used as a reference for output values
uses: gittools/actions/gitversion/execute@v4.1.0
env:
DOTNET_GITVERSION_TELEMETRY_OPTOUT: 1
with:
configFilePath: ./GitVersion.yml

- name: Extract version information
id: extract-version
run: |
# Read GitVersion output and replace PullRequest with Patch
VERSION="${{ steps.version_step.outputs.SemVer }}"
# make 0.1.0-PullRequest99.190 to 0.1.0-Patch99.190
VERSION=$(echo "$VERSION" | sed 's/PullRequest/Patch/g')
FULL_SEMVER="${{ steps.version_step.outputs.FullSemVer }}"
MAJOR_MINOR_PATCH="${{ steps.version_step.outputs.MajorMinorPatch }}"
GIT_HASH="${{ steps.version_step.outputs.Sha }}"
GIT_TAG="${{ steps.version_step.outputs.PreReleaseTag }}"
GIT_BRANCH="${{ steps.version_step.outputs.BranchName }}"
COMMIT_COUNT="${{ steps.version_step.outputs.CommitsSinceVersionSource }}"
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

# Create version.txt content
cat > version-$VERSION.txt << EOF
version=$VERSION
major_minor_patch=$MAJOR_MINOR_PATCH
full_semver=$FULL_SEMVER
git_hash=$GIT_HASH
git_tag=$GIT_TAG
git_branch=$GIT_BRANCH
commit_count=$COMMIT_COUNT
build_date=$BUILD_DATE
EOF

# Output version for other steps
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "MAJOR_MINOR_PATCH=$MAJOR_MINOR_PATCH" >> $GITHUB_OUTPUT
echo "FULL_SEMVER=$FULL_SEMVER" >> $GITHUB_OUTPUT
echo "GIT_HASH=$GIT_HASH" >> $GITHUB_OUTPUT
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_OUTPUT
echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_OUTPUT
echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_OUTPUT

# Display version info
echo "Generated version: $VERSION"
echo "Major minor patch: $MAJOR_MINOR_PATCH"
echo "Full semver: $FULL_SEMVER"
echo "Git hash: $GIT_HASH"
echo "Git branch: $GIT_BRANCH"
echo "Commit count: $COMMIT_COUNT"
echo "Build date: $BUILD_DATE"
echo "version.txt content:"
cat version-$VERSION.txt

- name: Update project files with version
run: |
chmod +x scripts/updateVersion.sh
bash scripts/updateVersion.sh

- name: Upload version.txt as artifact
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: version-info
path: version-${{ steps.extract-version.outputs.VERSION }}.txt
retention-days: ${{ env.retention_days }}
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
Expand Down
99 changes: 96 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,100 @@ on:
- main
pull_request:

env:
retention_days: 3

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full git history for version calculation

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v4.1.0
with:
versionSpec: "6.3.x"

- name: Determine Version
id: version_step # step id used as a reference for output values
uses: gittools/actions/gitversion/execute@v4.1.0
env:
DOTNET_GITVERSION_TELEMETRY_OPTOUT: 1
with:
configFilePath: ./GitVersion.yml

- name: Extract version information
id: extract-version
run: |
# Read GitVersion output and replace PullRequest with Patch
VERSION="${{ steps.version_step.outputs.SemVer }}"
# make 0.1.0-PullRequest99.190 to 0.1.0-Patch99.190
VERSION=$(echo "$VERSION" | sed 's/PullRequest/Patch/g')
FULL_SEMVER="${{ steps.version_step.outputs.FullSemVer }}"
MAJOR_MINOR_PATCH="${{ steps.version_step.outputs.MajorMinorPatch }}"
GIT_HASH="${{ steps.version_step.outputs.Sha }}"
GIT_TAG="${{ steps.version_step.outputs.PreReleaseTag }}"
GIT_BRANCH="${{ steps.version_step.outputs.BranchName }}"
COMMIT_COUNT="${{ steps.version_step.outputs.CommitsSinceVersionSource }}"
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

# Create version.txt content
cat > version-$VERSION.txt << EOF
version=$VERSION
major_minor_patch=$MAJOR_MINOR_PATCH
full_semver=$FULL_SEMVER
git_hash=$GIT_HASH
git_tag=$GIT_TAG
git_branch=$GIT_BRANCH
commit_count=$COMMIT_COUNT
build_date=$BUILD_DATE
EOF

# Output version for other steps
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "MAJOR_MINOR_PATCH=$MAJOR_MINOR_PATCH" >> $GITHUB_OUTPUT
echo "FULL_SEMVER=$FULL_SEMVER" >> $GITHUB_OUTPUT
echo "GIT_HASH=$GIT_HASH" >> $GITHUB_OUTPUT
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_OUTPUT
echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_OUTPUT
echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_OUTPUT

# Display version info
echo "Generated version: $VERSION"
echo "Major minor patch: $MAJOR_MINOR_PATCH"
echo "Full semver: $FULL_SEMVER"
echo "Git hash: $GIT_HASH"
echo "Git branch: $GIT_BRANCH"
echo "Commit count: $COMMIT_COUNT"
echo "Build date: $BUILD_DATE"
echo "version.txt content:"
cat version-$VERSION.txt

- name: Update project files with version
run: |
chmod +x scripts/updateVersion.sh
bash scripts/updateVersion.sh

- name: Upload version.txt as artifact
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: version-info
path: version-${{ steps.extract-version.outputs.VERSION }}.txt
retention-days: ${{ env.retention_days }}
- uses: actions/setup-node@v3
with:
node-version: current
- run: npm ci
- run: npm test
- name: upload junit
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: junit
path: junit.xml
retention-days: ${{ env.retention_days }}
# displays in summary page
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
Expand All @@ -36,13 +115,27 @@ jobs:
path: junit.xml
- run: npm run test:coverage
- name: upload code coverage
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: Report-CodeCoverage
path: coverage
retention-days: ${{ env.retention_days }}
# adds coverage comment to pr
- name: parse coverage
uses: danhunsaker/clover-reporter-action@v0.2.17-clover
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
clover-file: ./coverage/clover.xml

automerge:
needs: tests
name: Auto-merge PR if tests pass
if: (github.actor == 'dependabot[bot]' || github.actor == 'imgbot[bot]') && needs.tests.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Merge PR
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
merge-method: squash
pull-request-number: ${{ github.event.pull_request.number }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ samples/output.md
junit.xml
output-*.json
funktechno-sqlsimpleparser*
version*txt
52 changes: 52 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
workflow: TrunkBased/preview1

mode: ContinuousDelivery
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
semantic-version-format: Strict
commit-message-incrementing: Enabled

branches:
main:
regex: ^main$
increment: Patch
is-main-branch: true
is-release-branch: true
prevent-increment:
of-merged-branch: true
track-merge-target: true
track-merge-message: true

dev:
regex: ^dev$
increment: None
mode: ContinuousDelivery
label: alpha
prevent-increment:
of-merged-branch: true
track-merge-message: true
source-branches:
- main

# builds directly off feature/<name> branches
feature:
regex: ^features?[/-](?<BranchName>.+)
increment: None
label: "beta{BranchName}"
track-merge-message: true
source-branches:
- main
- dev

pull-request:
regex: ^(pull|pull-requests|pr)[/-](?<Number>\d+)
increment: None
mode: ContinuousDelivery
label: zeta{Number}
prevent-increment:
of-merged-branch: true
track-merge-message: true
source-branches:
- main
- dev
- feature
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@funktechno/sqlsimpleparser",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
80 changes: 80 additions & 0 deletions scripts/convert-npm-audit-outdated-to-sonar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// convert-npm-audit-outdated-to-sonar.js
import fs from "node:fs";

// Load npm audit and outdated reports
const audit = JSON.parse(fs.readFileSync("npm-audit.json", "utf8"));
const outdated = JSON.parse(fs.readFileSync("npm-outdated.json", "utf8"));

const issues = [];

// Convert npm audit vulnerabilities
for (const vuln of Object.values(audit.vulnerabilities || {})) {
// Normalize ruleId: prefer CVE/advisory ID if available, else package name
let ruleId = vuln.name;
if (Array.isArray(vuln.via) && vuln.via.length > 0) {
const via = vuln.via[0];
if (typeof via === "string") {
ruleId = via;
} else if (via && typeof via === "object") {
// advisory id or source if present
ruleId = via.source || via.url || via.title || vuln.name;
}
}

issues.push({
engineId: "npm-audit",
ruleId: String(ruleId), // force to string
severity: mapSeverity(vuln.severity),
type: "VULNERABILITY",
primaryLocation: {
message: `${vuln.name} ${vuln.range} is vulnerable (${vuln.via
.map((v) => (typeof v === "string" ? v : v.title || v.source || ""))
.join(", ")})`,
filePath: "package-lock.json",
textRange: { startLine: 1, endLine: 1 },
},
});
}

// Convert npm outdated packages
for (const [pkg, info] of Object.entries(outdated)) {
if (info.current !== info.latest) {
issues.push({
engineId: "npm-outdated",
ruleId: "outdated-dependency",
severity: mapOutdatedSeverity(info.current, info.latest),
type: "CODE_SMELL",
primaryLocation: {
message: `Package ${pkg} is outdated (current ${info.current}, latest ${info.latest})`,
filePath: "package.json",
textRange: { startLine: 1, endLine: 1 },
},
});
}
}

// Severity mapping helpers
function mapSeverity(sev) {
switch (sev) {
case "low":
return "INFO";
case "moderate":
return "MINOR";
case "high":
return "MAJOR";
case "critical":
return "BLOCKER";
default:
return "MINOR";
}
}

function mapOutdatedSeverity(current, latest) {
// crude version check: major bump = MAJOR, minor/patch = MINOR
const [cMaj] = current.split(".");
const [lMaj] = latest.split(".");
return cMaj !== lMaj ? "MAJOR" : "MINOR";
}

// Write combined report
fs.writeFileSync("npm-sonar.json", JSON.stringify({ issues }, null, 2));
Loading