Created
October 15, 2024 12:40
-
-
Save alexsavio/ff3265c614222cac5d875e30c63a5b23 to your computer and use it in GitHub Desktop.
Raw Github Actions template to run cargo lambda packaging
This file contains hidden or 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: "Template: Test, compile and zip Rust Lambdas" | |
on: | |
workflow_call: | |
inputs: | |
function-name: | |
required: true | |
type: string | |
description: | | |
"Name of the lambda function to check and zip" | |
working-directory: | |
required: true | |
type: string | |
description: | | |
"Directory in which the lambda project is located" | |
outputs: | |
artifact-name: | |
description: "Name of the Github Artifact that has been uploaded" | |
value: ${{ jobs.zip.outputs.artifact-name }} | |
permissions: | |
id-token: write | |
contents: read | |
pull-requests: write | |
packages: write | |
jobs: | |
code-check: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{ inputs.working-directory }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Rust | |
uses: actions-rust-lang/setup-rust-toolchain@v1 | |
with: | |
components: rustfmt, clippy | |
- name: Cache cargo registry | |
uses: actions/cache@v3 | |
continue-on-error: false | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
key: cargo-build-cache | |
- name: Clippy Check | |
run: cargo clippy --bin ${{ inputs.function-name }} --all-targets --all-features | |
- name: Rustfmt Check | |
uses: actions-rust-lang/rustfmt@v1 | |
- name: Test | |
run: | | |
cargo test --bin ${{ inputs.function-name }} | |
zip: | |
needs: code-check | |
if: (needs.code-check.result == 'success' || needs.code-check.result == 'skipped') | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{ inputs.working-directory }} | |
outputs: | |
artifact-name: ${{ steps.result.outputs.artifact-name }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Rust | |
uses: actions-rust-lang/setup-rust-toolchain@v1 | |
with: | |
components: rustfmt, clippy | |
- name: Cache cargo registry | |
uses: actions/cache@v3 | |
continue-on-error: false | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
key: cargo-build-cache | |
- name: Release lambda | |
id: build | |
run: | | |
pip install cargo-lambda | |
cargo lambda build --bin ${{ inputs.function-name }} --x86-64 --release --output-format zip | |
echo "artifact-path=target/lambda/${{ inputs.function-name }}/bootstrap.zip" >> $GITHUB_OUTPUT | |
- name: Assert that the zip artifact exists | |
run: | | |
if [ ! -f "${{ steps.build.outputs.artifact-path }}" ]; then | |
echo "${{ steps.build.outputs.artifact-path }} not found" | |
exit 1 | |
fi | |
- name: Upload artifact | |
id: ghupload | |
uses: actions/upload-artifact@v4 | |
with: | |
path: ${{ inputs.working-directory }}/${{ steps.build.outputs.artifact-path }} | |
name: ${{ inputs.function-name }} | |
overwrite: true | |
compression-level: 0 | |
if-no-files-found: error | |
retention-days: 3 | |
- name: Result | |
id: result | |
run: | | |
echo "artifact-name=${{ inputs.function-name }}" >> $GITHUB_OUTPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment