diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1890101 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,77 @@ +name: Release + +on: + push: + branches: [main] + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: write + +jobs: + publish-and-sync: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v6 + with: + node-version: 22.x + cache: npm + registry-url: https://registry.npmjs.org + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + - name: Resolve package version + id: pkg + run: | + VERSION=$(node -p "require('./package.json').version") + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Check if version is already on npm + id: npm + run: | + VERSION="${{ steps.pkg.outputs.version }}" + if npm view "sequelize-jest-kit@${VERSION}" version 2>/dev/null | grep -q .; then + echo "published=true" >> "$GITHUB_OUTPUT" + echo "Version ${VERSION} is already on npm; skipping publish and GitHub release." + else + echo "published=false" >> "$GITHUB_OUTPUT" + fi + + - name: Publish to npm + if: steps.npm.outputs.published == 'false' + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish + + - name: Create GitHub release + if: steps.npm.outputs.published == 'false' + uses: softprops/action-gh-release@v2 + with: + tag_name: v${{ steps.pkg.outputs.version }} + name: v${{ steps.pkg.outputs.version }} + generate_release_notes: true + + - name: Merge main into develop and push + if: steps.npm.outputs.published == 'false' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git fetch origin develop + git checkout -B develop origin/develop + git merge origin/main --no-edit -m "chore: sync develop with main after v${{ steps.pkg.outputs.version }}" + git push origin develop