diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 3d031a7..b09156a 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,40 +1,3 @@ -# بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم -# This file is part of forehead. -# -# Copyright (C) 2026-Present Afsall Inc. -# SPDX-License-Identifier: Apache-2.0 OR MIT -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Alternatively, this file is available under the MIT License: -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - name: CD on: push: @@ -65,46 +28,87 @@ jobs: echo "changed=true" >> "$GITHUB_OUTPUT" fi - publish: + changelog: needs: detect if: needs.detect.outputs.changed == 'true' runs-on: ubuntu-latest permissions: contents: write - packages: write steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install Rust uses: dtolnay/rust-toolchain@v1 with: toolchain: stable - - name: Publish forehead-core - run: | - VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') - if ! curl -s "https://crates.io/api/v1/crates/forehead-core" | grep -q "\"version\":\"$VERSION\""; then - cargo publish -p forehead-core - else - echo "forehead-core v$VERSION already exists, skipping" - fi - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - - name: Publish forehead-cli + - uses: Swatinem/rust-cache@v2 + - name: Install changelogger + run: cargo install changelogger-cli --version 0.2.2 + - name: Generate CHANGELOG + run: changelogger changelog generate --dir prdoc --output CHANGELOG.md --release "${{ needs.detect.outputs.version }}" + - name: Commit and tag run: | - VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') - if ! curl -s "https://crates.io/api/v1/crates/forehead-cli" | grep -q "\"version\":\"$VERSION\""; then - cargo publish -p forehead-cli - else - echo "forehead-cli v$VERSION already exists, skipping" - fi + VERSION=${{ needs.detect.outputs.version }} + git config user.name "changelogger-bot" + git config user.email "bot@github.com" + git add CHANGELOG.md + git commit -m "changelog: auto-generate for v${VERSION}" || true + git tag "v${VERSION}" + git push origin "v${VERSION}" + + crates-io: + needs: detect + if: needs.detect.outputs.changed == 'true' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + - uses: Swatinem/rust-cache@v2 + - name: Install changelogger + run: cargo install changelogger-cli --version 0.2.2 + - name: Publish to crates.io + run: changelogger publish env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - - name: Install changelogger - run: cargo install changelogger-cli --version 0.2.1 - - name: Generate and update CHANGELOG.md - run: | - VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') - changelogger changelog generate --from "v${VERSION}" --output CHANGELOG.md - changelogger changelog bump --current "$VERSION" --from "v${VERSION}" - git add CHANGELOG.md - git commit -m "chore: update CHANGELOG.md for v${VERSION}" || true \ No newline at end of file + container: + needs: detect + if: needs.detect.outputs.changed == 'true' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}},value=v${{ needs.detect.outputs.version }} + type=semver,pattern={{major}}.{{minor}},value=v${{ needs.detect.outputs.version }} + type=raw,value=latest + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.github/workflows/command-prdoc.yml b/.github/workflows/command-prdoc.yml deleted file mode 100644 index d020ddb..0000000 --- a/.github/workflows/command-prdoc.yml +++ /dev/null @@ -1,114 +0,0 @@ -# بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم -# This file is part of forehead. -# -# Copyright (C) 2026-Present Afsall Inc. -# SPDX-License-Identifier: Apache-2.0 OR MIT -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Alternatively, this file is available under the MIT License: -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -name: Command PRDoc -on: - workflow_dispatch: - inputs: - pr: - type: number - description: Number of the Pull Request - required: true - bump: - type: choice - description: Default bump level for all crates - default: "patch" - required: true - options: - - "patch" - - "minor" - - "major" - - "none" - audience: - type: choice - description: Audience of the PRDoc - default: "developer" - required: true - options: - - "developer" - - "user" - - "operator" - overwrite: - type: boolean - description: Overwrite existing PRDoc - default: false - required: true - -permissions: - contents: write - pull-requests: write - -jobs: - cmd-prdoc: - runs-on: ubuntu-latest - timeout-minutes: 20 - steps: - - name: Get PR branch - id: pr - env: - GH_TOKEN: ${{ github.token }} - run: | - BRANCH=$(gh pr view "${{ inputs.pr }}" --json headRefName -q '.headRefName') - echo "branch=$BRANCH" >> "$GITHUB_OUTPUT" - - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ steps.pr.outputs.branch }} - - - name: Install changelogger - run: cargo install changelogger-cli --version 0.2.1 - - - name: Generate PRDoc - env: - GH_TOKEN: ${{ github.token }} - run: | - FLAGS="" - if [ "${{ inputs.overwrite }}" = "true" ]; then - FLAGS="--force" - fi - changelogger prdoc generate \ - --pr "${{ inputs.pr }}" \ - --bump "${{ inputs.bump }}" \ - --audience "${{ inputs.audience }}" \ - $FLAGS - - - name: Commit PRDoc - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: "Add prdoc for PR #${{ inputs.pr }} (auto-generated)" - file_pattern: "prdoc/*.prdoc" \ No newline at end of file diff --git a/.github/workflows/prdoc.yml b/.github/workflows/prdoc.yml index 910269e..0bdfe13 100644 --- a/.github/workflows/prdoc.yml +++ b/.github/workflows/prdoc.yml @@ -1,40 +1,3 @@ -# بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم -# This file is part of forehead. -# -# Copyright (C) 2026-Present Afsall Inc. -# SPDX-License-Identifier: Apache-2.0 OR MIT -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Alternatively, this file is available under the MIT License: -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - name: PRDoc on: pull_request: @@ -52,10 +15,13 @@ jobs: with: fetch-depth: 0 ref: ${{ github.head_ref }} - + - name: Install Rust + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + - uses: Swatinem/rust-cache@v2 - name: Install changelogger - run: cargo install changelogger-cli --version 0.2.1 - + run: cargo install changelogger-cli --version 0.2.2 - name: Generate PRDoc id: generate env: @@ -64,28 +30,23 @@ jobs: PR_NUM=${{ github.event.pull_request.number }} PRDOC="prdoc/pr_${PR_NUM}.prdoc" if [ -f "$PRDOC" ]; then - echo "PRDoc already exists at $PRDOC — validating only" + echo "PRDoc already exists — validating only" echo "generated=false" >> "$GITHUB_OUTPUT" else - changelogger prdoc generate --pr "$PR_NUM" --force --bump patch + changelogger prdoc generate --pr "$PR_NUM" --force echo "generated=true" >> "$GITHUB_OUTPUT" fi - python3 -c " -import re -with open('$PRDOC') as f: - c = f.read() -c = c.replace('crates: [ ]', 'crates:\n - name: forehead-core\n bump: patch\n - name: forehead-cli\n bump: patch') -with open('$PRDOC', 'w') as f: - f.write(c) -" - - name: Validate PRDoc env: CI: "true" run: | PRDOC="prdoc/pr_${{ github.event.pull_request.number }}.prdoc" changelogger prdoc validate "$PRDOC" - + - name: Validate Backport Rules + if: startsWith(github.base_ref, 'stable') || startsWith(github.base_ref, 'release') + run: | + PRDOC="prdoc/pr_${{ github.event.pull_request.number }}.prdoc" + changelogger prdoc validate --branch "${{ github.base_ref }}" "$PRDOC" - name: Commit PRDoc if: steps.generate.outputs.generated == 'true' uses: stefanzweifel/git-auto-commit-action@v5 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c2d8dec..350ee65 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,40 +1,3 @@ -# بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم -# This file is part of forehead. -# -# Copyright (C) 2026-Present Afsall Inc. -# SPDX-License-Identifier: Apache-2.0 OR MIT -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Alternatively, this file is available under the MIT License: -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - name: Release on: push: @@ -56,31 +19,44 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@v1 with: - toolchain: nightly-2026-02-18 + toolchain: stable - uses: Swatinem/rust-cache@v2 - - name: Extract version from Cargo.toml - id: version - run: | - VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') - echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" - name: Build run: cargo build --release --workspace - - - name: Install changelogger - run: cargo install changelogger-cli --version 0.2.1 - - - name: Generate changelog - run: | - changelogger changelog generate --from "${{ github.ref_name }}" --output CHANGELOG.md - changelogger changelog bump --current "${{ steps.version.outputs.VERSION }}" - - name: Create GitHub Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release create "${{ github.ref_name }}" \ - --title "forehead v${{ steps.version.outputs.VERSION }}" \ - --generate-notes + TAG="${{ github.ref_name }}" + if gh release view "$TAG" &>/dev/null; then + echo "Release $TAG already exists — skipping" + else + NOTES="" + if [ -f CHANGELOG.md ]; then + NOTES="--notes-file CHANGELOG.md" + fi + gh release create "$TAG" \ + --title "forehead $TAG" \ + $NOTES + fi + + crates-io: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + - uses: Swatinem/rust-cache@v2 + - name: Install changelogger + run: cargo install changelogger-cli --version 0.2.2 + - name: Publish to crates.io + run: changelogger publish + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} container: runs-on: ubuntu-latest @@ -97,22 +73,20 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract version from Cargo.toml + - name: Extract version from tag id: version - run: | - VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') - echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" + run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" - name: Build and push uses: docker/build-push-action@v6 with: context: . push: true tags: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.version.outputs.VERSION }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest labels: | org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} - org.opencontainers.image.description=Create and maintain file headers for code license + org.opencontainers.image.description=A tool for creating and maintaining file headers for code license org.opencontainers.image.licenses=Apache-2.0 OR MIT cache-from: type=gha cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 2d23b0d..bc1cffd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,7 +152,7 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "forehead-cli" -version = "0.1.4" +version = "0.2.1" dependencies = [ "anyhow", "clap", @@ -165,7 +165,7 @@ dependencies = [ [[package]] name = "forehead-core" -version = "0.1.4" +version = "0.2.1" dependencies = [ "regex", "serde", diff --git a/Cargo.toml b/Cargo.toml index 8f3cb3f..ddf6d76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ ] [workspace.package] -version = "0.1.4" +version = "0.2.1" edition = "2021" license = "Apache-2.0 OR MIT" authors = ["Afsall Inc"] diff --git a/changelogger.toml b/changelogger.toml index 36117eb..6b0980b 100644 --- a/changelogger.toml +++ b/changelogger.toml @@ -39,7 +39,6 @@ version = 1 schema = "prdoc/schema_user.json" output_dir = "prdoc" prdoc_folders = ["prdoc"] -template = "prdoc/.template.prdoc" [audiences] developer = "Developer" diff --git a/mise.toml b/mise.toml index caf5ec2..a563c08 100644 --- a/mise.toml +++ b/mise.toml @@ -56,5 +56,5 @@ description = "Run all CI checks" depends = ["fmt", "headers", "clippy", "test", "build"] [tasks.changelogger] -description = "Install changelogger-cli v0.2.1" -run = "cargo install changelogger-cli --version 0.2.1" \ No newline at end of file +description = "Install changelogger-cli v0.2.2" +run = "cargo install changelogger-cli --version 0.2.2" \ No newline at end of file diff --git a/packages/forehead-cli/Cargo.toml b/packages/forehead-cli/Cargo.toml index 38add31..36e2a29 100644 --- a/packages/forehead-cli/Cargo.toml +++ b/packages/forehead-cli/Cargo.toml @@ -9,7 +9,7 @@ description.workspace = true readme = "README.md" [dependencies] -forehead-core = { path = "../forehead-core", version = "0.1.4" } +forehead-core = { path = "../forehead-core", version = "0.2.1" } clap.workspace = true anyhow.workspace = true serde.workspace = true diff --git a/packages/forehead-core/src/lib.rs b/packages/forehead-core/src/lib.rs index 3870788..938cf04 100644 --- a/packages/forehead-core/src/lib.rs +++ b/packages/forehead-core/src/lib.rs @@ -52,7 +52,7 @@ pub mod error; pub mod header; pub mod template; -const SKIP_DIRS: &[&str] = &[".git", "target", "node_modules"]; +const SKIP_DIRS: &[&str] = &[".git", "target", "node_modules", ".github"]; const SKIP_FILES: &[&str] = &["Cargo.lock", "forehead.toml"]; pub struct Forehead { diff --git a/prdoc/.template.prdoc b/prdoc/.template.prdoc deleted file mode 100644 index 829cf50..0000000 --- a/prdoc/.template.prdoc +++ /dev/null @@ -1,13 +0,0 @@ -# PRDoc: Pull Request Documentation -# Fill in the ... placeholders with meaningful content. - ---- -title: ... - -doc: - - audience: Developer - description: | - ... - -crates: [ ] ---- \ No newline at end of file diff --git a/prdoc/pr_17.prdoc b/prdoc/pr_17.prdoc new file mode 100644 index 0000000..e736e9d --- /dev/null +++ b/prdoc/pr_17.prdoc @@ -0,0 +1,16 @@ +--- +title: Changelogger upgrade +author: balqaasem +pr: 17 + +doc: + - audience: Developer + description: | + Changes for PR #17 + +crates: + - name: forehead-cli + bump: minor + - name: forehead-core + bump: minor +---