diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..3e624a1 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,43 @@ +name: Docker CI + +on: + workflow_dispatch: + push: + branches: + - "master" + tags: + - "v*" + pull_request: + branches: + - "master" + +env: + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + +jobs: + docker_hub: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: floride/scrounch_backend + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=floride/scrounch_backend:latest + cache-to: type=inline diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ef5c337 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: Release CI + +on: + push: + tags: + - "v*" + +jobs: + build_and_tests: + uses: ./.github/workflows/rust.yml + release: + runs-on: ubuntu-latest + needs: build_and_tests + steps: + - uses: actions/checkout@v4 + - name: Fetch tags + run: git fetch --tags --force + - name: Get current tag annotation + id: tag-data + uses: ericcornelissen/git-tag-annotation-action@v2 + - name: Create GitHub release + uses: Roang-zero1/github-create-release-action@v3 + with: + version_regex: ^v.* + release_text: ${{ steps.tag-data.outputs.git-tag-annotation }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - if: failure() + name: Delete tag + uses: prompt/actions-delete-tag@v1 + add_binary: + needs: release + name: Release Binary ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: [x86_64-pc-windows-gnu, x86_64-unknown-linux-musl] + steps: + - uses: actions/checkout@v4 + - name: Compile and release + uses: rust-build/rust-build.action@v1.4.5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + RUSTTARGET: ${{ matrix.target }} + EXTRA_FILES: "README.md LICENSE" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..fd8b944 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,48 @@ +name: Rust CI + +on: + push: + branches: "*" + pull_request: + branches: "*" + workflow_call: + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - run: cargo check --verbose --workspace + + test: + name: test + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - run: cargo test --all-features --workspace + + clippy: + name: linter + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy + - run: cargo clippy -- -D warnings + + format: + name: format + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt + - run: cargo fmt -- --check