From ca955848d84239a63ac6b5857a9b5f29c45c1255 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Tue, 2 Apr 2024 15:59:16 -0700 Subject: [PATCH] add ci Signed-off-by: karthik2804 --- .github/workflows/build.yaml | 181 +++++++++++++++++++++++++++++++++++ Cargo.lock | 1 + Cargo.toml | 7 +- 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..d8b167d --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,181 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Build and package +on: + push: + branches: [main] + tags: ["v*"] + pull_request: + branches: [main] + workflow_dispatch: + +# TODO: better way? +permissions: + contents: write + +env: + PROGRAM_NAME: trigger-command + +jobs: + lint: + name: Lint Rust code + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: 1.74 + + - name: Install dependencies + run: | + rustup component add rustfmt + rustup component add clippy + + - name: lint code + run: make lint + + - name: Run Clippy + run: cargo clippy --all -- -D warnings + - name: Cancel everything if linting fails + if: failure() + uses: andymckay/cancel-action@0.2 + + build: + name: Build plugin + runs-on: ${{ matrix.config.os }} + strategy: + fail-fast: false + matrix: + config: + - { target: "x86_64-unknown-linux-gnu", os: "ubuntu-20.04", arch: "amd64", extension: ""} + - { target: "aarch64-unknown-linux-gnu", os: "ubuntu-20.04", arch: "aarch64", extension: "", extraArg: "--features openssl/vendored" } + - { target: "x86_64-apple-darwin", os: "macos-latest", arch: "amd64", extension: "" } + - { target: "aarch64-apple-darwin", os: "macos-latest", arch: "aarch64", extension: "" } + - { target: "x86_64-pc-windows-msvc", os: "windows-latest", arch: "amd64", extension: ".exe" } + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + with: + shared-key: "${{ runner.os }}-lint-${{ hashFiles('./Cargo.lock') }}" + cache-on-failure: "true" + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: 1.74 + targets: ${{ matrix.config.target }} + - name: Install Spin + uses: rajatjindal/setup-actions/spin@main + with: + version: "v0.8.0" + - name: Install pluginify + shell: bash + run: spin plugins install --url https://github.com/itowlson/spin-pluginify/releases/download/canary/pluginify.json --yes + - name: Set up for cross-compiled linux aarch64 build + if: matrix.config.target == 'aarch64-unknown-linux-gnu' + run: | + sudo apt update + sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + echo '[target.aarch64-unknown-linux-gnu]' >> ${HOME}/.cargo/config.toml + echo 'linker = "aarch64-linux-gnu-gcc"' >> ${HOME}/.cargo/config.toml + - name: Build plugin binary + run: cargo build --release --target ${{ matrix.config.target }} ${{ matrix.config.extraArg }} + - name: Copy plugin binary to standard location + shell: bash + run: cp target/${{ matrix.config.target }}/release/${{ env.PROGRAM_NAME}}${{ matrix.config.extension }} target/release/${{ env.PROGRAM_NAME}}${{ matrix.config.extension }} + + - name: Pluginify plugin binary + run: spin pluginify --arch ${{ matrix.config.arch }} + - name: Archive pluginified + uses: actions/upload-artifact@v3 + with: + name: ${{ env.PROGRAM_NAME}}-${{ matrix.config.os }}-${{ matrix.config.arch }} + path: | + *.tar.gz + *.json + + package: + name: Package plugin + if: github.event_name == 'push' + runs-on: ubuntu-latest + needs: build + steps: + - name: Install Spin + uses: rajatjindal/setup-actions/spin@main + with: + version: "v2.0.0" + - name: Install pluginify + shell: bash + run: spin plugins install --url https://github.com/itowlson/spin-pluginify/releases/download/canary/pluginify.json --yes + + - name: set the release version (tag) + if: startsWith(github.ref, 'refs/tags/v') + shell: bash + run: echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + - name: set the release version (main) + if: github.ref == 'refs/heads/main' + shell: bash + run: echo "RELEASE_VERSION=canary" >> $GITHUB_ENV + - name: set the release version (TEST TEST TEST) + if: github.event_name == 'pull_request' + shell: bash + run: echo "RELEASE_VERSION=precanary" >> $GITHUB_ENV + + - name: Download artifacts + uses: actions/download-artifact@v3 + - name: Display structure of downloaded files + run: ls -R + - name: pluginify it + run: | + spin pluginify --merge --release-url-base https://github.com/fermyon/spin-trigger-command/releases/download/${{ env.RELEASE_VERSION }}/ >${{ env.PROGRAM_NAME }}.json + - name: Display merged manifest + run: cat ${{ env.PROGRAM_NAME }}.json + + # Handle versioned release + - name: Upload tars to Github release + if: startsWith(github.ref, 'refs/tags/v') + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: "**/*.tar.gz" + file_glob: true + tag: ${{ github.ref }} + - name: Upload manifest to Github release + if: startsWith(github.ref, 'refs/tags/v') + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.PROGRAM_NAME }}.json + tag: ${{ github.ref }} + + # Handle canary release + - name: Delete canary tag + if: github.ref == 'refs/heads/main' + uses: dev-drprasad/delete-tag-and-release@v0.2.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: canary + - name: Recreate canary tag and release + if: github.ref == 'refs/heads/main' + uses: ncipollo/release-action@v1.10.0 + with: + tag: canary + allowUpdates: true + prerelease: true + - name: Upload tars to Github release + if: github.ref == 'refs/heads/main' + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: "**/*.tar.gz" + file_glob: true + tag: canary + - name: Upload manifest to Github release + if: github.ref == 'refs/heads/main' + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.PROGRAM_NAME }}.json + tag: canary \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 77aca93..43846e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4961,6 +4961,7 @@ dependencies = [ "anyhow", "async-trait", "clap", + "openssl", "serde", "spin-app", "spin-core", diff --git a/Cargo.toml b/Cargo.toml index 0ead259..6cc0868 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,12 +18,17 @@ async-trait = "0.1" clap = { version = "3.1.15", features = ["derive", "env"] } serde = "1.0" spin-app = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" } -spin-core = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" } +spin-core = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" } spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" } tokio = { version = "1.23", features = ["full"] } tracing = { version = "0.1", features = ["log"] } tracing-subscriber = { version = "0.3.7", features = ["env-filter"] } wasmtime-wasi = { version = "18.0.1", features = ["tokio"] } +[target.'cfg(target_os = "linux")'.dependencies] +# This needs to be an explicit dependency to enable +# '--features openssl/vendored', which is used for Linux releases. +openssl = { version = "0.10" } + [workspace.dependencies] wit-bindgen = "0.16.0"