diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..d9a1642 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,75 @@ + + +on: + workflow_call: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Check for [skip] in PR title + id: check_skip + run: | + pr_title="${{ github.event.pull_request.title }}" + + if [[ "$pr_title" == "[Skip]"* ]]; then + echo "skip=true" >> $GITHUB_ENV + else + echo "skip=false" >> $GITHUB_ENV + fi + + - name: Verify PR title + if: env.skip == 'false' + id: determine_increment + run: | + pr_title="${{ github.event.pull_request.title }}" + latest_tag=${{ env.latest_tag }} + + # 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" == "[Minor]"* ]]; then + minor=$((minor + 1)) + patch=0 + elif [[ "$pr_title" == "[Patch]"* ]]; then + patch=$((patch + 1)) + else + echo "PR title must start with [Major], [Minor], or [Patch]." + exit 1 + fi + + # Construct the new tag + new_tag="v${major}.${minor}.${patch}" + echo "new_tag=$new_tag" >> $GITHUB_ENV + + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - 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: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4feef9f..0d4f461 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,11 @@ permissions: jobs: build: + uses: ./.github/workflows/build.yml + + release: if: github.event.pull_request.merged == true + needs: build runs-on: ubuntu-latest steps: @@ -18,16 +22,11 @@ jobs: with: fetch-depth: 0 - - name: Set up Node.js - uses: actions/setup-node@v4 + - name: Download build artifacts + uses: actions/download-artifact@v4 with: - node-version: 'lts/*' - - - name: Install dependencies - run: npm i - - - name: Build the project - run: npm run build + name: dist + path: dist/ - name: Debug dist folder run: ls -la dist @@ -164,8 +163,8 @@ jobs: rollback: runs-on: ubuntu-latest - needs: build - if: failure() # Only run if the build job fails + needs: release + if: failure() # Only run if the release job fails steps: - name: Download tag artifact @@ -205,3 +204,4 @@ jobs: npm deprecate $tag "Deprecation reason" || echo "Package not found" env: NPM_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }} +