diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a09a078..f37b23f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,9 @@ name: CI -on: [push, pull_request] +on: [push] jobs: - CI: + build: runs-on: ubuntu-latest steps: - name: Checkout code @@ -17,19 +17,8 @@ jobs: node-version: 20 cache: 'npm' - - name: Installing dependencies + - name: Install dependencies run: npm ci - name: Build package run: npm run build -- --filter=svelte-reveal - - # - name: Testing - # run: npm run test - - # - name: SonarCloud Scan - # uses: sonarsource/sonarcloud-github-action@master - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - # with: - # projectBaseDir: packages/svelte-reveal diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a063011..7537a89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,16 +1,52 @@ -name: 'Publish to NPM' +name: Release on: pull_request: types: + - opened + - synchronize - closed branches: - main jobs: + check-version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.package-version.outputs.current-version }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get current version + id: package-version + uses: martinbeentjes/npm-get-version-action@v1.3.1 + with: + path: 'packages/svelte-reveal' + + - name: Get latest tag + id: latest-tag + uses: 'WyriHaximus/github-action-get-previous-tag@v1' + + - name: Compare versions + uses: madhead/semver-utils@v4 + id: version + with: + version: ${{ steps.latest-tag.outputs.tag }} + + - name: Detected invalid semver upgrade + if: ${{ steps.package-version.outputs.current-version != steps.version.outputs.inc-major && steps.package-version.outputs.current-version != steps.version.outputs.inc-minor && steps.package-version.outputs.current-version != steps.version.outputs.inc-patch }} + uses: actions/github-script@v7 + with: + script: | + core.setFailed('Invalid semver upgrade (${{ steps.latest-tag.outputs.tag }} -> ${{ steps.package-version.outputs.current-version }})') + release: - if: github.event.pull_request.merged == true && github.ref == 'refs/heads/main' runs-on: ubuntu-latest + needs: check-version + if: github.event.pull_request.merged == true steps: - name: Checkout code uses: actions/checkout@v4 @@ -23,7 +59,7 @@ jobs: node-version: 20 cache: 'npm' - - name: Installing dependencies + - name: Install dependencies run: npm ci - name: Build package @@ -40,12 +76,6 @@ jobs: package: ./packages/svelte-reveal/package.json strategy: upgrade - - name: Get Package Version - id: package-version - uses: martinbeentjes/npm-get-version-action@master - with: - path: 'packages/svelte-reveal' - - name: Extract release notes id: extract-release-notes uses: ffurrer2/extract-release-notes@v1 @@ -58,8 +88,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ steps.package-version.outputs.current-version }} - release_name: ${{ steps.package-version.outputs.current-version }} + tag_name: ${{ needs.check-version.outputs.version }} + release_name: ${{ needs.check-version.outputs.version }} draft: false prerelease: false body: ${{ steps.extract-release-notes.outputs.release_notes }} @@ -71,6 +101,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create-release.outputs.upload_url }} - asset_path: ./packages/svelte-reveal/svelte-reveal-${{ steps.package-version.outputs.current-version }}.tgz - asset_name: svelte-reveal-${{ steps.package-version.outputs.current-version }}.tgz + asset_path: ./packages/svelte-reveal/svelte-reveal-${{ needs.check-version.outputs.version }}.tgz + asset_name: svelte-reveal-${{ needs.check-version.outputs.version }}.tgz asset_content_type: application/gzip