Skip to content

Commit

Permalink
Improve auto deployment using Github Action (#7)
Browse files Browse the repository at this point in the history
* Remove old training and example files for model updates

* Remove examples module and update dependencies

* Implement directory traversal function in filesystem.rs

* Update GitHub Actions workflow and refactor code with `From` traits

* Update CD workflow to use checkout v3 and refactor versioning steps

* Add `.secrets` to .gitignore

* Add `cd_local` task to Justfile for local testing

* Fix quotes in version outputs in GitHub workflow CD script

* Fix duplicate version output properties in CD workflow

* Fix missing YAML indentation in GitHub Actions CD workflow

* Disable CD workflows and comments

* Add CD workflow with branch triggers and automated tasks

* Remove 'examples' subcommand and associated test logic

* Fix duplicate push commands in CD workflow

* Refactor CD workflow and streamline version retrieval script

* Update CD workflow to run tests on PR merge

* Simplify version comparison logic in CD workflow

* Remove duplicate cargo-bump installation in CI workflow

* Add macOS to CI workflow matrix

* Fix version output references in GitHub CD workflow

* Simplify version environment variables in CD workflow

* Fix redundant apt-get update/install commands in cd.yml

* Remove redundant installation of 'jq' in CI workflow

* Fix CD workflow dependency duplication

* Update Rust setup in GitHub Actions workflow

* Update CD workflow to include stable Rust toolchain

* Add caching for cargo registry, index, and build in CD workflow

* Fix matrix variable and improve consistency in CD workflow

* Delete unused .cargo/config.toml file

* Refactor GitHub Actions: Add linting, setup, and integration steps

* Refactor GitHub Actions workflow for Rust toolchain

* Consolidate cargo cache paths in GitHub Actions workflow

* Add actor email configuration in GitHub Actions CD workflow

* Add Rust nightly toolchain to CD workflow
  • Loading branch information
oleander authored May 28, 2024
1 parent 79a3dda commit bee36c6
Showing 10 changed files with 180 additions and 119 deletions.
5 changes: 0 additions & 5 deletions .cargo/config.toml

This file was deleted.

151 changes: 140 additions & 11 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -2,32 +2,161 @@ name: CD

on:
push:
tags:
- v*
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
workflow_dispatch: {}

env:
CARGO_TERM_COLOR: always

jobs:
deploy:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Rust
- name: Checkout code
uses: actions/checkout@v3

- name: Setup nightly toolchain
uses: actions-rs/toolchain@v1
with:
components: rustfmt, clippy
toolchain: nightly
override: true
- name: Cargo test

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-nightly-${{ hashFiles('**/Cargo.lock') }}

- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: test
command: clippy
args: -- -D warnings

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
test:
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
rust: [nightly, stable]
runs-on: ${{ matrix.os }}
continue-on-error: false
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
profile: minimal

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}

- name: Run integration tests
run: ./tools/test.sh
run: |
cargo build --release
cargo test --release
./tools/test.sh
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Cargo publish

deploy:
needs: [test, lint]
runs-on: ubuntu-latest
continue-on-error: false
steps:
- name: Checkout code
uses: actions/checkout@v3

- run: sudo apt-get install jq

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
default: true
toolchain: stable

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-stable-${{ hashFiles('**/Cargo.lock') }}

- name: Install cargo-bump
run: cargo install cargo-bump

- name: Previous version
id: prev_version
run: echo "::set-output name=version::$(./scripts/current-version)"
shell: bash

- name: Bump version using cargo-bump
run: cargo bump patch

- name: Next version
id: next_version
run: echo "::set-output name=version::$(./scripts/current-version)"
shell: bash

- name: Check that version number was bumped
if: ${{ steps.prev_version.outputs.version == steps.next_version.outputs.version }}
run: exit 1

- 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 config user.name "${{ github.actor }}"
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
git add Cargo.lock Cargo.toml
git commit -m "Update dependencies for version ${{ steps.next_version.outputs.version }}"
git tag -a "v${{ steps.next_version.outputs.version }}" -m "Release v${{ steps.next_version.outputs.version }}"
- 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${{ steps.next_version.outputs.version }}"
- 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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
http-cacache/*
.secrets
.env.local
47 changes: 23 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -21,3 +21,5 @@ docker-build:

docker-run IMG CMD:
docker run --rm -v $PWD:/git-ai -w /git-ai -it {{IMG}} {{CMD}}
cd_local:
act
3 changes: 3 additions & 0 deletions scripts/current-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version'
Loading

0 comments on commit bee36c6

Please sign in to comment.