-
Notifications
You must be signed in to change notification settings - Fork 1
chore: add CI/CD and release workflows #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,256 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| version_bump: | ||
| description: 'Version bump type' | ||
| required: true | ||
| default: 'patch' | ||
| type: choice | ||
| options: | ||
| - patch | ||
| - minor | ||
| - major | ||
|
|
||
| concurrency: | ||
| group: release | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| env: | ||
| CARGO_TERM_COLOR: always | ||
| RUSTFLAGS: -Dwarnings | ||
| BINARY_NAME: olx-tracker | ||
|
|
||
| jobs: | ||
| checks: | ||
| name: Checks | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| components: rustfmt, clippy | ||
| - uses: Swatinem/rust-cache@v2 | ||
| - name: Format | ||
| run: cargo fmt --all -- --check | ||
| - name: Clippy | ||
| run: cargo clippy --all-targets | ||
| - name: Test | ||
| run: cargo test | ||
|
|
||
| create-tag: | ||
| name: Create Tag | ||
| needs: checks | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version: ${{ steps.bump.outputs.version }} | ||
| tag: ${{ steps.bump.outputs.tag }} | ||
| commit_sha: ${{ steps.commit.outputs.sha }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Verify on main branch | ||
| run: | | ||
| if [ "${{ github.ref }}" != "refs/heads/main" ]; then | ||
| echo "::error::Release must be run from main branch, not ${{ github.ref }}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Get current version | ||
| id: current | ||
| run: | | ||
| # Get version from Cargo.toml | ||
| VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "Current version: $VERSION" | ||
|
|
||
| - name: Bump version | ||
| id: bump | ||
| run: | | ||
| CURRENT="${{ steps.current.outputs.version }}" | ||
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" | ||
|
|
||
| case "${{ inputs.version_bump }}" in | ||
| major) | ||
| MAJOR=$((MAJOR + 1)) | ||
| MINOR=0 | ||
| PATCH=0 | ||
| ;; | ||
| minor) | ||
| MINOR=$((MINOR + 1)) | ||
| PATCH=0 | ||
| ;; | ||
| patch) | ||
| PATCH=$((PATCH + 1)) | ||
| ;; | ||
| esac | ||
|
|
||
| NEW_VERSION="$MAJOR.$MINOR.$PATCH" | ||
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | ||
| echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT | ||
| echo "New version: $NEW_VERSION" | ||
|
|
||
| - name: Update Cargo.toml | ||
| run: | | ||
| sed -i 's/^version = ".*"/version = "${{ steps.bump.outputs.version }}"/' Cargo.toml | ||
| cat Cargo.toml | head -10 | ||
|
|
||
| - name: Commit and tag | ||
| id: commit | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add Cargo.toml | ||
| git commit -m "chore: bump version to ${{ steps.bump.outputs.version }}" | ||
| echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | ||
| git tag -a "${{ steps.bump.outputs.tag }}" -m "Release ${{ steps.bump.outputs.tag }}" | ||
| git push origin main --follow-tags | ||
|
|
||
| build: | ||
| name: Build (${{ matrix.target }}) | ||
| needs: create-tag | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - os: macos-latest | ||
| target: aarch64-apple-darwin | ||
| artifact: olx-tracker-macos-arm64 | ||
| - os: ubuntu-latest | ||
| target: x86_64-unknown-linux-gnu | ||
| artifact: olx-tracker-linux-x64 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ needs.create-tag.outputs.tag }} | ||
|
|
||
| - name: Install Rust | ||
| uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| targets: ${{ matrix.target }} | ||
|
|
||
| - name: Cache | ||
| uses: Swatinem/rust-cache@v2 | ||
| with: | ||
| key: release-${{ matrix.target }} | ||
|
|
||
| - name: Build | ||
| run: cargo build --release --target ${{ matrix.target }} | ||
|
|
||
| - name: Package (Unix) | ||
| run: | | ||
| cd target/${{ matrix.target }}/release | ||
| tar -czvf ../../../${{ matrix.artifact }}.tar.gz ${{ env.BINARY_NAME }} | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: ${{ matrix.artifact }} | ||
| path: ${{ matrix.artifact }}.tar.gz | ||
|
|
||
| release: | ||
| name: Create Release | ||
| needs: [create-tag, build] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ needs.create-tag.outputs.tag }} | ||
|
|
||
| - name: Download artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| path: artifacts | ||
|
|
||
| - name: Get previous tag | ||
| id: prev_tag | ||
| run: | | ||
| PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | ||
| echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT | ||
| echo "Previous tag: $PREV_TAG" | ||
|
|
||
| - name: Build Changelog | ||
| id: changelog | ||
| uses: mikepenz/release-changelog-builder-action@v5 | ||
| with: | ||
| configurationJson: | | ||
| { | ||
| "categories": [ | ||
| { "title": "## Features", "labels": ["feature", "enhancement"] }, | ||
| { "title": "## Bug Fixes", "labels": ["bug", "fix"] }, | ||
| { "title": "## Documentation", "labels": ["documentation", "docs"] }, | ||
| { "title": "## Other Changes", "labels": [] } | ||
| ], | ||
| "template": "#{{CHANGELOG}}\n\n**Full Changelog**: #{{RELEASE_DIFF}}", | ||
| "pr_template": "- #{{TITLE}} (#{{NUMBER}})", | ||
| "empty_template": "No pull requests since last release." | ||
| } | ||
| fromTag: ${{ steps.prev_tag.outputs.tag }} | ||
| toTag: ${{ needs.create-tag.outputs.tag }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Create Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: ${{ needs.create-tag.outputs.tag }} | ||
| name: ${{ env.BINARY_NAME }} ${{ needs.create-tag.outputs.tag }} | ||
| body: | | ||
| ## Installation | ||
|
|
||
| Download the appropriate binary for your platform: | ||
|
|
||
| | Platform | File | | ||
| |----------|------| | ||
| | macOS (Apple Silicon) | `olx-tracker-macos-arm64.tar.gz` | | ||
| | Linux (x64) | `olx-tracker-linux-x64.tar.gz` | | ||
|
|
||
| ### Quick Install | ||
|
|
||
| ```bash | ||
| # Linux/macOS | ||
| tar -xzf olx-tracker-*.tar.gz | ||
| chmod +x olx-tracker | ||
| ./olx-tracker --help | ||
| ``` | ||
|
|
||
| ${{ steps.changelog.outputs.changelog }} | ||
| files: artifacts/**/*.tar.gz | ||
| draft: false | ||
| prerelease: false | ||
|
|
||
| cleanup: | ||
| name: Cleanup on failure | ||
| needs: [create-tag, build] | ||
| if: failure() && needs.create-tag.result == 'success' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Delete tag and revert commit | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| echo "Deleting tag ${{ needs.create-tag.outputs.tag }}..." | ||
| git push --delete origin ${{ needs.create-tag.outputs.tag }} || true | ||
|
|
||
| echo "Reverting version bump commit ${{ needs.create-tag.outputs.commit_sha }}..." | ||
| git pull origin main | ||
| git revert ${{ needs.create-tag.outputs.commit_sha }} --no-edit | ||
| git push origin main | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Cargo.lock not updated after version bump leaves repository in inconsistent state
When the release workflow bumps the version in Cargo.toml, it only commits Cargo.toml but does not regenerate Cargo.lock.
Click to expand
Mechanism
In the
create-tagjob, the version bump workflow:sed(line 103)git add Cargo.toml(line 111)The Cargo.lock file contains the package's own version metadata. After this commit, the repository will have:
X.Y.Z(new)X.Y.Z-1(old)Impact
This leaves the repository in an inconsistent state where Cargo.toml and Cargo.lock have mismatched versions. While
cargo buildwill fix this locally, the committed state in the repository is inconsistent, which could cause confusion or issues with reproducible builds.Recommendation
Add a step to regenerate Cargo.lock after updating Cargo.toml:
Was this helpful? React with 👍 or 👎 to provide feedback.