Improve auto deployment using Github Action #37
Workflow file for this run
This file contains 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
name: CD | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize, reopened, closed] | |
branches: | |
- main | |
workflow_dispatch: {} | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
continue-on-error: false | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
cargo install cargo-bump cargo-metadata | |
- name: Previous version | |
id: prev_version | |
run: ./scripts/current-version | |
- name: Bump version using cargo-bump | |
run: cargo bump patch | |
- name: Next version | |
id: next_version | |
run: ./scripts/current-version | |
- name: Check that version number was bumped | |
if: ${{ env.prev_version == env.next_version }} | |
run: exit 1 | |
env: | |
next_version: "${{ steps.next_version.outputs }}" | |
prev_version: "${{ steps.prev_version.outputs }}" | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: nightly | |
override: true | |
- name: Run integration tests | |
run: | | |
cargo build --release | |
cargo test --release | |
cargo fmt -- --check | |
cargo clippy -- -D warnings | |
./tools/test.sh | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
- name: Update dependencies & ensure version changed | |
if: ${{ github.event.pull_request.merged == true }} | |
run: cargo update --aggressive | |
- name: Commit changes and tag release | |
run: | | |
git add Cargo.lock Cargo.toml | |
git commit -m "Update dependencies for version ${{ env.next_version }}" | |
git tag -a "v${{ env.next_version }}" -m "Release v${{ env.next_version }}" | |
env: | |
next_version: "${{ steps.next_version.outputs }}" | |
- name: Publish to crates.io (Dry Run) | |
if: ${{ github.event.pull_request.merged != true }} | |
run: | | |
echo "Dry run: would publish to crates.io but skipping because this is a dry run." | |
- name: Push changes to main | |
if: ${{ github.event.pull_request.merged == true }} | |
run: | | |
git push origin main | |
git push origin "v${{ env.next_version }}" | |
env: | |
next_version: "${{ steps.next_version.outputs }}" | |
- name: Publish to crates.io (Actual Run) | |
if: ${{ github.event.pull_request.merged == true }} | |
uses: katyo/publish-crates@v2 | |
with: | |
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
- name: Success message | |
if: ${{ github.event.pull_request.merged == true }} | |
run: echo "Successfully published version ${{ env.next_version }}" | |
env: | |
next_version: ${{ steps.next_version.outputs }} |