diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1c48227..3070b4f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,9 +1,8 @@ on: - push: - branches: - - master pull_request: types: [opened, synchronize] + paths-ignore: + - .github/** jobs: build: @@ -25,19 +24,3 @@ jobs: run: cargo test - name: Check artifact weight run: ls -lh target/release/ - - publish: - needs: build - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/master' - steps: - - uses: actions/checkout@v4 - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable - override: true - - name: Publish to crates.io - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - run: cargo publish --no-verify diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..bff4ad4 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,113 @@ +name: Publish to crates.io + +on: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + override: true + + - name: Get version from tag + id: get_version + run: | + VERSION=${GITHUB_REF#refs/tags/v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT + + - name: Verify version matches tag + run: | + CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') + TAG_VERSION=${{ steps.get_version.outputs.version }} + echo "Cargo.toml version: $CARGO_VERSION" + echo "Git tag version: $TAG_VERSION" + if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then + echo "❌ Version mismatch: Cargo.toml has $CARGO_VERSION but tag is $TAG_VERSION" + exit 1 + fi + echo "✅ Version matches tag" + + - name: Generate changelog for release + id: changelog + run: | + # Extract the changelog section for this version + if [ -f "CHANGELOG.md" ]; then + # Use awk to extract the section between the current version and the next version + CHANGELOG_SECTION=$(awk "/^## \[${{ steps.get_version.outputs.version }}\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md) + + # If no section found, generate from git commits + if [ -z "$CHANGELOG_SECTION" ]; then + echo "No changelog section found for version ${{ steps.get_version.outputs.version }}" + echo "Generating changelog from git commits..." + + # Get the previous tag + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") + + if [ -n "$PREVIOUS_TAG" ]; then + echo "### Changes since $PREVIOUS_TAG" > temp_changelog.md + echo "" >> temp_changelog.md + git log --oneline --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> temp_changelog.md + else + echo "### Changes in this release" > temp_changelog.md + echo "" >> temp_changelog.md + git log --oneline --pretty=format:"- %s (%h)" -n 10 >> temp_changelog.md + fi + + CHANGELOG_SECTION=$(cat temp_changelog.md) + rm temp_changelog.md + fi + else + echo "No CHANGELOG.md found, generating from git commits..." + + # Get the previous tag + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") + + if [ -n "$PREVIOUS_TAG" ]; then + echo "### Changes since $PREVIOUS_TAG" > temp_changelog.md + echo "" >> temp_changelog.md + git log --oneline --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> temp_changelog.md + else + echo "### Changes in this release" > temp_changelog.md + echo "" >> temp_changelog.md + git log --oneline --pretty=format:"- %s (%h)" -n 10 >> temp_changelog.md + fi + + CHANGELOG_SECTION=$(cat temp_changelog.md) + rm temp_changelog.md + fi + + # Write to file for release update + echo "$CHANGELOG_SECTION" > release_notes.md + echo "Generated changelog for release page" + + - name: Update release with changelog + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.get_version.outputs.tag }} + body_path: release_notes.md + append_body: true + + - name: Run tests + run: cargo test + + - name: Publish to crates.io + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: | + echo "📦 Publishing to crates.io..." + cargo publish --no-verify + echo "✅ Successfully published to crates.io" diff --git a/Cargo.lock b/Cargo.lock index f39028c..eb7d421 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -486,7 +486,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "yabe-gitops" -version = "0.1.8" +version = "0.1.9" dependencies = [ "clap", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index eea53ee..b6d4921 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "yabe-gitops" description = "GitOps organizer" repository = "https://github.com/dvrkn/yabe" readme = "README.md" -version = "0.1.8" +version = "0.1.9" edition = "2021" keywords = ["gitops", "kubernetes", "argocd", "yaml", "helm"] license = "MIT"