From 9f6f941c03b498e410a56b52d833bac5f269d88d Mon Sep 17 00:00:00 2001 From: Paul Schifferer Date: Thu, 14 Nov 2024 21:07:23 -0800 Subject: [PATCH] Rust stuff --- .github/dependabot.yml | 22 +++++ .github/workflows/bump-version.yml | 32 +++++++ .github/workflows/debug.yml | 57 +++++++++++ .github/workflows/rust-ci.yml | 149 +++++++++++++++++++++++++++++ .github/workflows/rust-pr.yml | 42 ++++++++ .rust-version | 1 + Cargo.toml | 6 ++ SECURITY.md | 11 +++ src/lib.rs | 14 +++ 9 files changed, 334 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/bump-version.yml create mode 100644 .github/workflows/debug.yml create mode 100644 .github/workflows/rust-ci.yml create mode 100644 .github/workflows/rust-pr.yml create mode 100644 .rust-version create mode 100644 Cargo.toml create mode 100644 SECURITY.md create mode 100644 src/lib.rs diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f98a258 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,22 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "cargo" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + open-pull-requests-limit: 5 + assignees: + - "paulyhedral" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml new file mode 100644 index 0000000..0c6a105 --- /dev/null +++ b/.github/workflows/bump-version.yml @@ -0,0 +1,32 @@ +name: Bump version + +concurrency: ci-${{ github.ref }} + +on: + workflow_dispatch: + inputs: + bump: + description: "SemVer component to update" + type: choice + options: + - major + - minor + - patch + required: true + +jobs: + tag: + runs-on: ubuntu-latest + permissions: + contents: write + concurrency: publish + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Bump version and push tag + uses: anothrNick/github-tag-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + DEFAULT_BUMP: ${{ github.event.inputs.bump || 'minor' }} diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml new file mode 100644 index 0000000..05424ab --- /dev/null +++ b/.github/workflows/debug.yml @@ -0,0 +1,57 @@ +name: Debug + +on: + release: + types: + - published + - created + push: + branches: + - '*' + tags: + - '*' + +jobs: + debug: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Dump job context + env: + JOB_CONTEXT: ${{ toJson(job) }} + run: echo "$JOB_CONTEXT" + - name: Dump steps context + env: + STEPS_CONTEXT: ${{ toJson(steps) }} + run: echo "$STEPS_CONTEXT" + - name: Dump runner context + env: + RUNNER_CONTEXT: ${{ toJson(runner) }} + run: echo "$RUNNER_CONTEXT" + - name: Dump strategy context + env: + STRATEGY_CONTEXT: ${{ toJson(strategy) }} + run: echo "$STRATEGY_CONTEXT" + - name: Dump matrix context + env: + MATRIX_CONTEXT: ${{ toJson(matrix) }} + run: echo "$MATRIX_CONTEXT" + - name: Get current date + id: getbuilddate + run: | + echo "::set-output name=date::$(date -u)" + echo "::set-output name=isodate::$(date -u '+%Y-%m-%dT%H:%M:%S')" + echo "::set-output name=tagdate::$(date -u '+%Y%m%d%H%M%S')" + echo "::set-output name=timestamp::$(date -u '+%s')" + - name: 'Get Previous tag' + id: previoustag + uses: actions-ecosystem/action-get-latest-tag@v1 + with: + semver_only: true + initial_version: v0.0.0 + with_initial_version: true diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml new file mode 100644 index 0000000..e061be8 --- /dev/null +++ b/.github/workflows/rust-ci.yml @@ -0,0 +1,149 @@ +name: CI + +concurrency: ci-${{ github.ref }} + +on: + push: + branches: [develop] + paths: + - "src/**/*.rs" + - Cargo.toml + - .rust-version + workflow_dispatch: + +jobs: + tests: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: Linux + os: ubuntu-latest + target: x86_64-unknown-linux-musl + # - build: macos + # os: macos-latest + # target: x86_64-apple-darwin + + steps: + - uses: actions/checkout@v4 + - name: Get language version + id: get_lang_version + run: | + v=$(cat .rust-version) + echo "lang_version=$v" >> $GITHUB_OUTPUT + - name: Install Rust + # Or @nightly if you want + uses: dtolnay/rust-toolchain@stable + # Arguments to pass in + with: + # Make Rust compile to our target (defined in the matrix) + targets: ${{ matrix.target }} + # rust-version: ${{ steps.get_lang_version.outputs.lang_version }} + - name: Build + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --verbose --release --target ${{ matrix.target }} + - name: publish-docs + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./coverage + + # docs: + # needs: [tests] + # runs-on: ubuntu-latest + # concurrency: docs + # steps: + # - uses: actions/checkout@v4 + # - uses: actions/setup-python@v5 + # with: + # python-version: "3.11" + # - name: install-deps + # run: pip install -r requirements/docs.txt + # - name: make-docs + # run: cd docs && make html + # - name: publish-docs + # uses: peaceiris/actions-gh-pages@v4 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # publish_dir: ./docs/_build/html + + tag: + needs: [tests] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Bump version and push tag + uses: anothrNick/github-tag-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + DEFAULT_BUMP: patch + + publish: + needs: [tag] + runs-on: ubuntu-latest + concurrency: publish + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get latest tag + id: get_latest_tag + uses: actions-ecosystem/action-get-latest-tag@v1 + # - name: Publish + # env: + # GOPROXY: proxy.golang.org + # run: go list -m github.com/sweetrpg/common@${{ steps.get_latest_tag.outputs.tag }} + + notify: + needs: [tag] + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - repo: api-core.rs + - repo: catalog-api + - repo: catalog-data.rs + - repo: catalog-data-processor + - repo: catalog-objects.rs + - repo: catalog-web + - repo: client.rs + - repo: data-api + - repo: data-objects.rs + - repo: db.rs + - repo: initiative-api + - repo: initiative-data.rs + - repo: initiative-objects.rs + - repo: initiative-web + - repo: kv-api + - repo: kv-data.rs + - repo: kv-expression-processor + - repo: kv-key-processor + - repo: kv-objects.rs + - repo: kv-value-calculator + - repo: kv-web + - repo: library-api + - repo: library-data.rs + - repo: library-objects.rs + - repo: library-web + - repo: main-web + - repo: model-core.rs + - repo: shared-web + - repo: web-core.rs + steps: + - uses: juztcode/repo-ditpatch-action@v1 + continue-on-error: true + with: + event-type: api-core-published + token: ${{ secrets.REPO_ACCESS_TOKEN }} + repository: sweetrpg/${{ matrix.repo }} diff --git a/.github/workflows/rust-pr.yml b/.github/workflows/rust-pr.yml new file mode 100644 index 0000000..b3ccc14 --- /dev/null +++ b/.github/workflows/rust-pr.yml @@ -0,0 +1,42 @@ +name: PR + +on: + pull_request: + branches: [develop] + +jobs: + tests: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: Linux + os: ubuntu-latest + target: x86_64-unknown-linux-musl + # - build: macos + # os: macos-latest + # target: x86_64-apple-darwin + + steps: + - uses: actions/checkout@v4 + - name: Get language version + id: get_lang_version + run: | + v=$(cat .rust-version) + echo "lang_version=$v" >> $GITHUB_OUTPUT + - name: Install Rust + # Or @nightly if you want + uses: dtolnay/rust-toolchain@stable + # Arguments to pass in + with: + # Make Rust compile to our target (defined in the matrix) + targets: ${{ matrix.target }} + # rust-version: ${{ steps.get_lang_version.outputs.lang_version }} + - name: Build + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --verbose --release --target ${{ matrix.target }} diff --git a/.rust-version b/.rust-version new file mode 100644 index 0000000..a92432a --- /dev/null +++ b/.rust-version @@ -0,0 +1 @@ +1.82 diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..94d30c9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "sweetrpg-api-core" +version = "0.0.1" +edition = "2021" + +[dependencies] diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..7427b49 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,11 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ------- | ------------------ | +| > 0.0.1 | :white_check_mark: | + +## Reporting a Vulnerability + +File an issue. diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +}