diff --git a/.github/workflows/test-cbindgen-workflow.yml b/.github/workflows/test-cbindgen-workflow.yml new file mode 100644 index 0000000..2a3e77d --- /dev/null +++ b/.github/workflows/test-cbindgen-workflow.yml @@ -0,0 +1,94 @@ +name: Test CBindgen Workflow + +on: + schedule: + - cron: '0 0 * * *' # Run daily at midnight + workflow_dispatch: + push: + branches: [ master ] + tags: + - 'v1' + paths: + - 'action.yml' + - '.github/workflows/test-cbindgen-workflow.yml' + pull_request: + branches: [ master ] + paths: + - 'action.yml' + - '.github/workflows/test-cbindgen-workflow.yml' + +jobs: + test-custom-parameters: + runs-on: ubuntu-latest + steps: + - name: Checkout Test Repository + uses: actions/checkout@v4 + with: + repository: Sewer56/prs-rs + ref: d08599ed5473616f57d57a0966939e1a5dbda9b4 + - name: Test Custom Parameters + uses: Reloaded-Project/devops-rust-cbindgen@v1 + with: + rust-project-path: '.' + config-file: cbindgen_cpp.toml + output-header-file: bindings_cpp.hpp + upload-artifact: false + - name: Assert Generated Header File + shell: bash + run: | + if [ ! -f bindings_cpp.hpp ]; then + echo "Generated header file does not exist" + exit 1 + fi + + test-c-bindings: + runs-on: ubuntu-latest + steps: + - name: Checkout Test Repository + uses: actions/checkout@v4 + with: + repository: Sewer56/prs-rs + ref: d08599ed5473616f57d57a0966939e1a5dbda9b4 + - name: Test C Bindings + uses: Reloaded-Project/devops-rust-cbindgen@v1 + with: + config-file: cbindgen_c.toml + output-header-file: bindings_c.h + upload-artifact: false + - name: Assert Generated C Header File + shell: bash + run: | + if [ ! -f bindings_c.h ]; then + echo "Generated C header file does not exist" + exit 1 + fi + + test-artifact-creation: + runs-on: ubuntu-latest + steps: + - name: Checkout Test Repository + uses: actions/checkout@v4 + with: + repository: Sewer56/prs-rs + ref: d08599ed5473616f57d57a0966939e1a5dbda9b4 + - name: Generate Bindings and Create Artifact + uses: Reloaded-Project/devops-rust-cbindgen@v1 + with: + config-file: cbindgen_c.toml + output-header-file: bindings_c.h + upload-artifact: true + github-token: ${{ secrets.GITHUB_TOKEN }} + commit-updated-bindings: 'false' + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: C-Bindings-bindings_c.h + path: artifacts + - name: Assert Artifact Contents + shell: bash + run: | + cat artifacts/bindings_c.h + if [ ! -f artifacts/bindings_c.h ]; then + echo "Extracted artifact does not contain the expected header file" + exit 1 + fi \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a91fae5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2023 Sewer56 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..b6850f4 --- /dev/null +++ b/README.MD @@ -0,0 +1,59 @@ +
+ + reloaded Logo + + +

Generate bindings with cbindgen

+ +

+ + License + +

+
+ +This GitHub Action generates C bindings with cbindgen for a Rust project. + +## Inputs + +| Input | Required | Default | Description | +| ------------------------- | -------- | --------------- | ------------------------------------------------------------------------------ | +| `rust-project-path` | No | `.` | Path to the Rust project | +| `config-file` | Yes | `cbindgen.toml` | Configuration file for cbindgen | +| `output-header-file` | Yes | `bindings_c.h` | Path to the output header file generated by cbindgen | +| `upload-artifact` | No | `true` | Whether to upload the generated header file as an artifact | +| `github-token` | No | | A GitHub token for pushing to the repo. Example: `${{ secrets.GITHUB_TOKEN }}` | +| `commit-updated-bindings` | No | `false` | Whether to commit the updated bindings | + +## Example Usage + +```yaml +steps: + - uses: actions/checkout@v4 + - uses: Reloaded-Project/cbindgen-action@v1 + with: + rust-project-path: '.' + config-file: 'cbindgen.toml' + output-header-file: 'bindings_c.h' + upload-artifact: 'true' + github-token: ${{ secrets.GITHUB_TOKEN }} + commit-updated-bindings: 'true' +``` + +## Getting Artifacts + +If the `upload-artifact` input is set to `true`, the generated header file will be uploaded as +an artifact with the following name format: + +``` +C-Bindings- +``` + +For example, if the `output-header-file` input is set to `bindings_c.h`, the artifact name +will be `C-Bindings-bindings_c.h`. + +If you are not uploading an artifact, the generated header can be found at `${{ inputs.rust-project-path }}/${{ inputs.output-header-file }}`. + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index d4e7952..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# cbindgen diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..0eeacbf --- /dev/null +++ b/action.yml @@ -0,0 +1,72 @@ +# .github/actions/cbindgen-action/action.yml +name: 'Generate bindings with cbindgen' +description: 'Generates C bindings with cbindgen for a Rust project' +branding: + icon: 'hash' + color: 'red' + +inputs: + rust-project-path: + description: 'Path to the Rust project' + required: false + default: '.' + config-file: + description: 'Configuration file for cbindgen' + required: true + default: 'cbindgen.toml' + output-header-file: + description: 'Path to the output header file generated by cbindgen' + required: true + default: 'bindings_c.h' + upload-artifact: + description: 'Whether to upload the generated header file as an artifact' + required: false + default: 'true' + github-token: + description: 'A GitHub token for pushing to the repo. Example: `secrets.GITHUB_TOKEN`' + required: true + commit-updated-bindings: + description: 'Whether to commit the updated bindings' + required: false + default: 'false' + +runs: + using: 'composite' + steps: + # Rust preinstalled on runner + - name: Setup Rust Caching + uses: Swatinem/rust-cache@v2 + with: + key: ${{ inputs.target }} + cache-on-failure: true + + # Note: Cached by setup-rust-toolchain + - name: Install cbindgen + shell: bash + working-directory: ${{ inputs.rust-project-path }} + run: cargo install cbindgen + + - name: Generate bindings + shell: bash + working-directory: ${{ inputs.rust-project-path }} + run: cbindgen --config ${{ inputs.config-file }} --output ${{ inputs.output-header-file }} + + - name: Upload header file + if: ${{ inputs.upload-artifact == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: C-Bindings-${{ inputs.output-header-file }} + path: ${{ inputs.rust-project-path }}/${{ inputs.output-header-file }} + + - name: Commit updated bindings + if: ${{ inputs.commit-updated-bindings == 'true' }} + uses: stefanzweifel/git-auto-commit-action@v4 + env: + GITHUB_TOKEN: ${{ inputs.github-token }} + with: + commit_message: Update generated C bindings + branch: ${{ github.ref_name }} + commit_user_name: cbindgen-action + commit_user_email: actions@github.com + commit_author: cbindgen-action + file_pattern: ${{ inputs.output-header-file }} \ No newline at end of file diff --git a/assets/reloaded-logo.png b/assets/reloaded-logo.png new file mode 100644 index 0000000..090fb3a Binary files /dev/null and b/assets/reloaded-logo.png differ