diff --git a/.github/README.md b/.github/README.md index f418489..592a997 100644 --- a/.github/README.md +++ b/.github/README.md @@ -58,7 +58,7 @@ pipx install "$(ls dist/*.whl | head -n 1)" Install a published release artifact with `pipx`: ```bash -pipx install https://github.com//StyleCheck/releases/download/vX.Y.Z/splinter3d_style-X.Y.Z-py3-none-any.whl +pipx install https://github.com/Splinter3D/StyleCheck/releases/download/vX.Y.Z/splinter3d_style-X.Y.Z-py3-none-any.whl splinter3d_style ``` @@ -68,7 +68,7 @@ Add this repository and a release tag to your `.pre-commit-config.yaml`: ```yaml repos: - - repo: https://github.com//StyleCheck + - repo: https://github.com/Splinter3D/StyleCheck rev: vX.Y.Z hooks: - id: splinter3d-style diff --git a/.github/workflows/backmerge-main-to-dev.yml b/.github/workflows/backmerge-main-to-dev.yml new file mode 100644 index 0000000..ed554ac --- /dev/null +++ b/.github/workflows/backmerge-main-to-dev.yml @@ -0,0 +1,60 @@ +name: backmerge-main-to-dev + +on: + pull_request_target: + branches: + - main + types: + - closed + +permissions: + contents: read + pull-requests: write + +jobs: + open-backmerge-pr: + if: >- + github.event.pull_request.merged == true && + startsWith(github.event.pull_request.head.ref, 'hotfix/') && + github.event.pull_request.head.ref != 'hotfix/release-main' + runs-on: ubuntu-latest + + steps: + - name: Open back-merge pull request + run: | + repo="${{ github.repository }}" + api_url="https://api.github.com/repos/${repo}/pulls" + title="chore(backmerge): main into dev after ${{ github.event.pull_request.head.ref }}" + head_branch="main" + base_branch="dev" + + existing_pr="$(curl --silent \ + --url "${api_url}?state=open&head=${{ github.repository_owner }}:${head_branch}&base=${base_branch}" \ + --header "Authorization: Bearer ${GITHUB_TOKEN}" \ + --header "Accept: application/vnd.github+json" \ + --header "X-GitHub-Api-Version: 2022-11-28")" + + if echo "$existing_pr" | grep -q '"number":'; then + echo "An open back-merge PR from main to dev already exists." + exit 0 + fi + + payload="$(cat <- + github.event.pull_request.merged == true && + github.event.pull_request.base.ref == 'dev' && + github.event.pull_request.head.ref != 'release/dev' + runs-on: ubuntu-latest + environment: + name: release-rc + + steps: + - name: Check out dev + uses: actions/checkout@v4 + with: + ref: dev + fetch-depth: 0 + + - name: Fetch tags + run: git fetch --force --tags origin + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install release tooling + run: python -m pip install --upgrade pip commitizen tomlkit + + - name: Prepare release branch + id: prepare + run: | + tag="$(./scripts/next-tag.sh rc)" + python_version="$(./scripts/tag-to-python-version.sh "$tag")" + release_branch="release/dev" + + cz changelog --unreleased-version="$tag" + ./scripts/check-versions.sh --fix "$tag" + git add CHANGELOG.md pyproject.toml + + if git diff --cached --quiet; then + echo "has_changes=false" >> "$GITHUB_OUTPUT" + echo "release_branch=$release_branch" >> "$GITHUB_OUTPUT" + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git checkout -B "$release_branch" + git commit -m "chore(release): ${python_version}" + git push --force-with-lease origin HEAD:"$release_branch" + + echo "has_changes=true" >> "$GITHUB_OUTPUT" + echo "release_branch=$release_branch" >> "$GITHUB_OUTPUT" + echo "python_version=$python_version" >> "$GITHUB_OUTPUT" + + - name: Open or update release PR + if: steps.prepare.outputs.has_changes == 'true' + run: | + repo="${{ github.repository }}" + head_branch="${{ steps.prepare.outputs.release_branch }}" + base_branch="dev" + title="chore(release): ${{ steps.prepare.outputs.python_version }}" + body="Automated release preparation PR for \`dev\`." + api_url="https://api.github.com/repos/${repo}/pulls" + + existing_pr="$(curl --silent \ + --url "${api_url}?state=open&head=${{ github.repository_owner }}:${head_branch}&base=${base_branch}" \ + --header "Authorization: Bearer ${GITHUB_TOKEN}" \ + --header "Accept: application/vnd.github+json" \ + --header "X-GitHub-Api-Version: 2022-11-28")" + + if echo "$existing_pr" | grep -q '"number":'; then + echo "Release PR from ${head_branch} to ${base_branch} already exists." + exit 0 + fi + + payload="$(cat <- + github.event.pull_request.merged == true && + github.event.pull_request.base.ref == 'main' && + github.event.pull_request.head.ref != 'hotfix/release-main' + runs-on: ubuntu-latest + environment: + name: release + + steps: + - name: Check out main + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + - name: Fetch tags + run: git fetch --force --tags origin + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install release tooling + run: python -m pip install --upgrade pip commitizen tomlkit + + - name: Prepare release branch + id: prepare + run: | + tag="$(./scripts/next-tag.sh stable)" + python_version="$(./scripts/tag-to-python-version.sh "$tag")" + release_branch="hotfix/release-main" + + cz changelog --unreleased-version="$tag" + ./scripts/check-versions.sh --fix "$tag" + git add CHANGELOG.md pyproject.toml + + if git diff --cached --quiet; then + echo "has_changes=false" >> "$GITHUB_OUTPUT" + echo "release_branch=$release_branch" >> "$GITHUB_OUTPUT" + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git checkout -B "$release_branch" + git commit -m "chore(release): ${python_version}" + git push --force-with-lease origin HEAD:"$release_branch" + + echo "has_changes=true" >> "$GITHUB_OUTPUT" + echo "release_branch=$release_branch" >> "$GITHUB_OUTPUT" + echo "python_version=$python_version" >> "$GITHUB_OUTPUT" + + - name: Open or update release PR + if: steps.prepare.outputs.has_changes == 'true' + run: | + repo="${{ github.repository }}" + head_branch="${{ steps.prepare.outputs.release_branch }}" + base_branch="main" + title="chore(release): ${{ steps.prepare.outputs.python_version }}" + body="Automated release preparation PR for \`main\`." + api_url="https://api.github.com/repos/${repo}/pulls" + + existing_pr="$(curl --silent \ + --url "${api_url}?state=open&head=${{ github.repository_owner }}:${head_branch}&base=${base_branch}" \ + --header "Authorization: Bearer ${GITHUB_TOKEN}" \ + --header "Accept: application/vnd.github+json" \ + --header "X-GitHub-Api-Version: 2022-11-28")" + + if echo "$existing_pr" | grep -q '"number":'; then + echo "Release PR from ${head_branch} to ${base_branch} already exists." + exit 0 + fi + + payload="$(cat <> "$GITHUB_OUTPUT" + echo "prerelease=$prerelease" >> "$GITHUB_OUTPUT" + echo "environment_name=$environment_name" >> "$GITHUB_OUTPUT" + + build: + runs-on: ubuntu-latest + needs: prepare steps: - name: Check out repository uses: actions/checkout@v7 with: + ref: refs/tags/${{ needs.prepare.outputs.tag_name }} fetch-depth: 0 - name: Set up Python @@ -34,37 +98,17 @@ jobs: name: dist path: dist/* - publish-prerelease: - if: contains(github.ref_name, '-rc.') - runs-on: ubuntu-latest - environment: - name: release-rc - needs: build - - steps: - - name: Download build artifacts - uses: actions/download-artifact@v7 - with: - name: dist - path: dist - - - name: Create GitHub prerelease - uses: softprops/action-gh-release@v3 - with: - files: dist/* - generate_release_notes: true - prerelease: true - - publish-release: - if: ${{ !contains(github.ref_name, '-rc.') }} + publish: runs-on: ubuntu-latest - needs: build environment: - name: release + name: ${{ needs.prepare.outputs.environment_name }} + needs: + - prepare + - build steps: - name: Download build artifacts - uses: actions/download-artifact@v7 + uses: actions/download-artifact@v8 with: name: dist path: dist @@ -72,5 +116,8 @@ jobs: - name: Create GitHub release uses: softprops/action-gh-release@v3 with: + tag_name: ${{ needs.prepare.outputs.tag_name }} + name: "Release: ${{ needs.prepare.outputs.tag_name }}" files: dist/* generate_release_notes: true + prerelease: ${{ needs.prepare.outputs.prerelease == 'true' }} diff --git a/.github/workflows/tag-on-merge.yml b/.github/workflows/tag-on-merge.yml index dd8c731..b9df1a7 100644 --- a/.github/workflows/tag-on-merge.yml +++ b/.github/workflows/tag-on-merge.yml @@ -20,55 +20,37 @@ jobs: tag-dev: if: >- github.event.pull_request.merged == true && - github.event.pull_request.base.ref == 'dev' + github.event.pull_request.base.ref == 'dev' && + github.event.pull_request.head.ref == 'release/dev' runs-on: ubuntu-latest environment: name: release-rc + outputs: + tag_name: ${{ steps.version.outputs.tag }} steps: - - name: Check out base branch - uses: actions/checkout@v7 + - name: Check out dev + uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.base.ref }} + ref: dev fetch-depth: 0 - name: Fetch tags run: git fetch --force --tags origin - name: Set up Python - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Install Commitizen - run: python -m pip install --upgrade pip commitizen tomlkit + - name: Install release tooling + run: python -m pip install --upgrade pip commitizen - name: Compute release candidate tag id: version run: | tag="$(./scripts/next-tag.sh rc)" - python_version="$(./scripts/tag-to-python-version.sh "$tag")" echo "tag=$tag" >> "$GITHUB_OUTPUT" - echo "python_version=$python_version" >> "$GITHUB_OUTPUT" - - - name: Update changelog and project version - run: | - tag="${{ steps.version.outputs.tag }}" - python_version="${{ steps.version.outputs.python_version }}" - - cz changelog --unreleased-version="$tag" - ./scripts/check-versions.sh --fix "$tag" - git add CHANGELOG.md pyproject.toml - - if git diff --cached --quiet; then - echo "No release file changes detected." - exit 0 - fi - - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git commit -m "chore(release): ${python_version}" - git push origin HEAD:dev - name: Create tag run: | @@ -81,62 +63,56 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git fetch origin dev --tags git tag -a "$tag" -m "Release candidate $tag" git push origin "$tag" + release-dev: + if: >- + github.event.pull_request.merged == true && + github.event.pull_request.base.ref == 'dev' && + github.event.pull_request.head.ref == 'release/dev' + needs: tag-dev + uses: ./.github/workflows/release.yml + secrets: inherit + with: + tag_name: ${{ needs.tag-dev.outputs.tag_name }} + prerelease: true + environment_name: release-rc + tag-main: if: >- github.event.pull_request.merged == true && - github.event.pull_request.base.ref == 'main' + github.event.pull_request.base.ref == 'main' && + github.event.pull_request.head.ref == 'hotfix/release-main' runs-on: ubuntu-latest environment: name: release + outputs: + tag_name: ${{ steps.version.outputs.tag }} steps: - - name: Check out base branch - uses: actions/checkout@v7 + - name: Check out main + uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.base.ref }} + ref: main fetch-depth: 0 - name: Fetch tags run: git fetch --force --tags origin - name: Set up Python - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Install Commitizen - run: python -m pip install --upgrade pip commitizen tomlkit + - name: Install release tooling + run: python -m pip install --upgrade pip commitizen - name: Compute stable tag id: version run: | tag="$(./scripts/next-tag.sh stable)" - python_version="$(./scripts/tag-to-python-version.sh "$tag")" echo "tag=$tag" >> "$GITHUB_OUTPUT" - echo "python_version=$python_version" >> "$GITHUB_OUTPUT" - - - name: Update changelog and project version - run: | - tag="${{ steps.version.outputs.tag }}" - python_version="${{ steps.version.outputs.python_version }}" - - cz changelog --unreleased-version="$tag" - ./scripts/check-versions.sh --fix "$tag" - git add CHANGELOG.md pyproject.toml - - if git diff --cached --quiet; then - echo "No release file changes detected." - exit 0 - fi - - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git commit -m "chore(release): ${python_version}" - git push origin HEAD:main - name: Create tag run: | @@ -149,6 +125,18 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git fetch origin main --tags git tag -a "$tag" -m "Release $tag" git push origin "$tag" + + release-main: + if: >- + github.event.pull_request.merged == true && + github.event.pull_request.base.ref == 'main' && + github.event.pull_request.head.ref == 'hotfix/release-main' + needs: tag-main + uses: ./.github/workflows/release.yml + secrets: inherit + with: + tag_name: ${{ needs.tag-main.outputs.tag_name }} + prerelease: false + environment_name: release diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..b56cbb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,25 @@ +## v0.1.3 (2026-07-08) + +### Fix + +- use tag name instead of branch for release + +## v0.1.2 (2026-07-08) + +### Fix + +- force ci run +- bump action versions +- use reusable workflow to release + +## v0.1.1 (2026-07-08) + +### Fix + +- dependabot crash and enforce release + +## v0.1.0 (2026-07-08) + +### Feat + +- add base project diff --git a/pyproject.toml b/pyproject.toml index 733b350..b87d356 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [project] name = "splinter3d_style" -version = "0.1.0" +version = "0.1.3" description = "A style checker for Splinter3D projects." readme = ".github/README.md" -requires-python = ">=3.10" +requires-python = ">=3.10,<4.0" [[project.authors]] name = "Mathieu BARLEON" email = "mathieu.barleon@splinter3d.com"