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
17 changes: 0 additions & 17 deletions .editorconfig

This file was deleted.

1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

59 changes: 59 additions & 0 deletions .github/scripts/check-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Check if coverage-summary.json exists
if [ ! -f "coverage/coverage-summary.json" ]; then
echo "❌ Coverage summary file not found!"
exit 1
fi

# Read coverage data
coverage=$(cat coverage/coverage-summary.json)

# Extract coverage percentages
statements=$(echo "$coverage" | grep -o '"statements":{[^}]*}' | grep -o '"pct":[0-9.]*' | cut -d: -f2)
branches=$(echo "$coverage" | grep -o '"branches":{[^}]*}' | grep -o '"pct":[0-9.]*' | cut -d: -f2)
functions=$(echo "$coverage" | grep -o '"functions":{[^}]*}' | grep -o '"pct":[0-9.]*' | cut -d: -f2)
lines=$(echo "$coverage" | grep -o '"lines":{[^}]*}' | grep -o '"pct":[0-9.]*' | cut -d: -f2)

# Display coverage summary
echo "Coverage Summary:"
echo " Statements: ${statements}%"
echo " Branches: ${branches}%"
echo " Functions: ${functions}%"
echo " Lines: ${lines}%"

# Define threshold
THRESHOLD=95

# Check thresholds
failed=()

if (( $(echo "$statements < $THRESHOLD" | bc -l) )); then
failed+=("Statements: ${statements}% (min: ${THRESHOLD}%)")
fi

if (( $(echo "$branches < $THRESHOLD" | bc -l) )); then
failed+=("Branches: ${branches}% (min: ${THRESHOLD}%)")
fi

if (( $(echo "$functions < $THRESHOLD" | bc -l) )); then
failed+=("Functions: ${functions}% (min: ${THRESHOLD}%)")
fi

if (( $(echo "$lines < $THRESHOLD" | bc -l) )); then
failed+=("Lines: ${lines}% (min: ${THRESHOLD}%)")
fi

# Report results
if [ ${#failed[@]} -gt 0 ]; then
echo ""
echo "❌ Coverage below threshold:"
for item in "${failed[@]}"; do
echo " $item"
done
exit 1
fi

echo ""
echo "✅ All coverage thresholds met"
exit 0
10 changes: 10 additions & 0 deletions .github/scripts/check-skip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

pr_title="$1"

if [[ "$pr_title" == "chore:"* ]]; then
echo "skip=true" >> $GITHUB_ENV
else
echo "skip=false" >> $GITHUB_ENV
fi
9 changes: 9 additions & 0 deletions .github/scripts/check-tag-exists.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

new_tag="$1"

if git rev-parse "refs/tags/$new_tag" >/dev/null 2>&1; then
echo "Tag $new_tag already exists."
exit 0
fi
10 changes: 10 additions & 0 deletions .github/scripts/create-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

mkdir temp_package
cp -r dist/. temp_package/
cp package.json temp_package/
cp README.md temp_package/
cp LICENSE temp_package/
cd temp_package
npm pack
9 changes: 9 additions & 0 deletions .github/scripts/create-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

new_tag="$1"

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag $new_tag
git push origin $new_tag
22 changes: 22 additions & 0 deletions .github/scripts/delete-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e

tag="$1"
github_token="$2"
repo="$3"

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Delete Git Tag
git tag -d $tag
git push origin :refs/tags/$tag

# Delete GitHub Release
release_id=$(curl -s -H "Authorization: token $github_token" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$repo/releases/tags/$tag" \
| jq -r '.id')
curl -X DELETE -H "Authorization: token $github_token" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$repo/releases/$release_id"
8 changes: 8 additions & 0 deletions .github/scripts/get-latest-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)
if [ -z "$latest_tag" ]; then
latest_tag="v0.0.0"
fi
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
7 changes: 7 additions & 0 deletions .github/scripts/setup-npmrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e

npm_token="$1"

echo "//registry.npmjs.org/:_authToken=$npm_token" > ~/.npmrc
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
29 changes: 29 additions & 0 deletions .github/scripts/verify-pr-title.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e

pr_title="$1"
latest_tag="$2"

# Extract major, minor, and patch components from the latest tag
major=$(echo $latest_tag | cut -d. -f1 | sed 's/v//')
minor=$(echo $latest_tag | cut -d. -f2)
patch=$(echo $latest_tag | cut -d. -f3)

# Determine the increment type based on PR title
if [[ "$pr_title" == "major:"* ]]; then
major=$((major + 1))
minor=0
patch=0
elif [[ "$pr_title" == "feat:"* ]]; then
minor=$((minor + 1))
patch=0
elif [[ "$pr_title" == "fix:"* ]]; then
patch=$((patch + 1))
else
echo "PR title must start with major:, feat:, or fix:."
exit 1
fi

# Construct the new tag
new_tag="v${major}.${minor}.${patch}"
echo "new_tag=$new_tag" >> $GITHUB_ENV
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build

on:
workflow_call:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for [skip] in PR title
id: check_skip
run: bash .github/scripts/check-skip.sh "${{ github.event.pull_request.title }}"

- name: Verify PR title
if: env.skip == 'false'
id: determine_increment
run: bash .github/scripts/verify-pr-title.sh "${{ github.event.pull_request.title }}" "${{ env.latest_tag }}"

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- name: Install dependencies
run: npm i

- name: Build the project
run: npm run build

- name: Run tests with coverage
run: npm run test:coverage

- name: Check coverage thresholds
run: bash .github/scripts/check-coverage.sh

- name: Upload build artifacts
if: github.event.pull_request.merged == true
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
129 changes: 129 additions & 0 deletions .github/workflows/main.yml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Build and Release

on:
pull_request:
types: [closed]

permissions:
contents: write # This grants write permissions to the token

jobs:
build:
uses: ./.github/workflows/build.yml

release:
if: github.event.pull_request.merged == true
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- name: Debug dist folder
run: ls -la dist

- name: Zip dist folder
run: zip -r gulp-msbuild.zip dist

- name: Get the latest tag
id: get_tag
run: bash .github/scripts/get-latest-tag.sh

- name: Check for [skip] in PR title
id: check_skip
run: bash .github/scripts/check-skip.sh "${{ github.event.pull_request.title }}"

- name: Determine version increment
if: env.skip == 'false'
id: determine_increment
run: bash .github/scripts/verify-pr-title.sh "${{ github.event.pull_request.title }}" "${{ env.latest_tag }}"

- name: Check if tag exists on remote
id: check_tag
run: bash .github/scripts/check-tag-exists.sh "${{ env.new_tag }}"

- name: Create new tag
if: env.skip == 'false' && steps.check_tag.outcome == 'success'
id: create_tag
run: bash .github/scripts/create-tag.sh "${{ env.new_tag }}"

- name: Create GitHub Release
if: env.skip == 'false' && steps.create_tag.outcome == 'success'
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ env.new_tag }}
release_name: ${{ env.new_tag }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Release Asset
if: env.skip == 'false'
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./gulp-msbuild.zip
asset_name: gulp-msbuild.zip
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up .npmrc
if: env.skip == 'false'
run: bash .github/scripts/setup-npmrc.sh "${{ secrets.NPM_PUBLISH_KEY }}"

- name: Create temp_package
if: env.skip == 'false'
run: bash .github/scripts/create-package.sh

- name: Publish to NPM
if: env.skip == 'false'
id: publish_npm
run: |
cd temp_package
npm publish --access public # Publish with public access
continue-on-error: true # Continue even if this step fails

- name: Upload tag as artifact
if: failure()
uses: actions/upload-artifact@v4
with:
name: failed-tag
path: <(echo ${{ env.new_tag }})

rollback:
runs-on: ubuntu-latest
needs: release
if: failure() # Only run if the release job fails

steps:
- name: Download tag artifact
uses: actions/download-artifact@v4
with:
name: failed-tag

- name: Delete release and tag
run: |
tag=$(cat failed-tag)
bash .github/scripts/delete-release.sh "$tag" "${{ secrets.GITHUB_TOKEN }}" "${{ github.repository }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Delete NPM Package
run: |
tag=$(cat failed-tag)
npm deprecate $tag "Deprecation reason" || echo "Package not found"
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }}

10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
node_modules/
temp/
coverage
.idea
dist/
coverage/
package-lock.json
*.log
.DS_Store
*.tgz
Loading