From c098dbd52ea1bb5b962042912554ee53fc6c7241 Mon Sep 17 00:00:00 2001 From: banditopazzo Date: Tue, 24 Oct 2023 14:48:56 +0200 Subject: [PATCH] feat(gh_workflow): update actions --- .github/workflows/build.yaml | 44 +++++++++ .github/workflows/quality.yaml | 73 +++++++++++++++ .github/workflows/release.yml | 166 ++++++++++++++++++--------------- .github/workflows/test.yml | 29 ------ Cargo.toml | 2 +- Cross.toml | 7 -- 6 files changed, 207 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/quality.yaml delete mode 100644 .github/workflows/test.yml delete mode 100644 Cross.toml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..e8986c5 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,44 @@ +name: Build +on: + pull_request: + branches: + - main + +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + profile: + - debug + - release + + platform: + - target: x86_64-unknown-linux-gnu + args: "" + + # For `musl` builds openssl must be vendored + - target: x86_64-unknown-linux-musl + args: "--features openssl-vendored" + + steps: + - name: Code checkout + uses: actions/checkout@v4 + + - name: Install Rust toolchain (stable) + uses: dtolnay/rust-toolchain@stable + with: + target: ${{ matrix.platform.target }} + + - name: Build Debug + if: ${{ matrix.profile == 'debug' }} + run: cargo build --locked --target=${{ matrix.platform.target }} --workspace --all-targets ${{ matrix.platform.args }} + + - name: Build Release + if: ${{ matrix.profile == 'release' }} + run: cargo build --locked --target=${{ matrix.platform.target }} --workspace --all-targets ${{ matrix.platform.args }} --release + + - name: Check build did not modify any files + run: test -z "$(git status --porcelain)" diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml new file mode 100644 index 0000000..2f5de9c --- /dev/null +++ b/.github/workflows/quality.yaml @@ -0,0 +1,73 @@ +name: Quality Checks +on: + pull_request: + branches: + - main + +jobs: + markdown-link-check: + name: Broken markdown links + runs-on: ubuntu-latest + steps: + - name: Code checkout + uses: actions/checkout@v4 + + - name: Run link check + uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + use-quiet-mode: "no" + use-verbose-mode: "yes" + check-modified-files-only: "no" + base-branch: ${{ github.head_ref }} + + fmt: + name: Formatting (rustfmt) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - target: x86_64-unknown-linux-gnu + + steps: + - name: Code checkout + uses: actions/checkout@v4 + + - name: Install Rust toolchain (stable) + uses: dtolnay/rust-toolchain@stable + with: + target: ${{ matrix.platform.target }} + components: rustfmt + + - name: Formatting (rustfmt) + run: cargo fmt -- --check + + lint: + name: Lint (clippy) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - target: x86_64-unknown-linux-gnu + args: "" + + # For `musl` builds openssl must be vendored + - target: x86_64-unknown-linux-musl + args: "--features openssl-vendored" + + steps: + - name: Code checkout + uses: actions/checkout@v4 + + - name: Install Rust toolchain (stable) + uses: dtolnay/rust-toolchain@stable + with: + target: ${{ matrix.platform.target }} + components: clippy + + - name: Clippy (all crates) + run: cargo clippy --locked --target=${{ matrix.platform.target }} --workspace --all-targets ${{ matrix.platform.args }} -- -D warnings + + - name: Check build did not modify any files + run: test -z "$(git status --porcelain)" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f73c00..077ad2d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,96 +1,108 @@ -name: Cosmo cli Release -on: [create] +name: Release +on: + push: + tags: + - '*' jobs: - release: - if: github.event_name == 'create' && github.event.ref_type == 'tag' - name: Release + vendored_archive: + name: Vendored archive runs-on: ubuntu-latest steps: - name: Code checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - # Compile x86_64 - - name: Install Rust toolchain (x86_64-unknown-linux-gnu) - uses: actions-rs/toolchain@v1 - with: - toolchain: "1.64" - target: x86_64-unknown-linux-gnu - - name: Install Rust toolchain (x86_64-unknown-linux-musl) - uses: actions-rs/toolchain@v1 - with: - toolchain: "1.64" - target: x86_64-unknown-linux-musl - - name: Build (x86_64-unknown-linux-gnu) - uses: actions-rs/cargo@v1 - with: - use-cross: true - toolchain: "1.64" - command: build - args: --release --target=x86_64-unknown-linux-gnu - - name: Build (x86_64-unknown-linux-musl) - uses: actions-rs/cargo@v1 - with: - use-cross: true - toolchain: "1.64" - command: build - args: --release --features "vendored-openssl" --target=x86_64-unknown-linux-musl - - # Create Release - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - draft: true - prerelease: false - body: "" - - # Create and upload vendored source - name: Create release directory - run: rsync -rv --exclude=.git . ../cosmo-${{ github.event.ref }} + run: rsync -rv --exclude=.git . ../cosmo-${{ env.REGISTRY_TAG }} + - name: Cargo vendor - working-directory: ../cosmo-${{ github.event.ref }} + working-directory: ../cosmo-${{ env.REGISTRY_TAG }} run: | mkdir ../vendor-cargo-home export CARGO_HOME=$(realpath ../vendor-cargo-home) mkdir -p .cargo cargo vendor >> .cargo/config.toml + - name: Create vendored source archive working-directory: ../ - run: tar cJf cosmo-${{ github.event.ref }}.tar.xz cosmo-${{ github.event.ref }} - - name: Upload cosmo vendored source archive - id: upload-release-cosmo-vendored-sources - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + id: create-archive + run: | + tar cJf cosmo-vendored-${{ env.REGISTRY_TAG }}.tar.xz cosmo-${{ env.REGISTRY_TAG }} + echo "archive_file_name=$(realpath ./cosmo-vendored-${{ env.REGISTRY_TAG }}.tar.xz)" >> $GITHUB_OUTPUT + + - name: Upload archive + uses: actions/upload-artifact@v3 + with: + name: binaries-${{ env.REGISTRY_TAG }} + path: ${{ steps.create-archive.outputs.archive_file_name }} + if-no-files-found: error + retention-days: 1 + + build: + name: Create binary + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - target: x86_64-unknown-linux-gnu + args: "" + + - target: x86_64-unknown-linux-musl + args: "--features openssl-vendored" + + steps: + - name: Code checkout + uses: actions/checkout@v4 + + - name: Install Rust toolchain (stable) + uses: dtolnay/rust-toolchain@stable with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ../cosmo-${{ github.event.ref }}.tar.xz - asset_name: cosmo-${{ github.event.ref }}.tar.xz - asset_content_type: application/x-xz + target: ${{ matrix.platform.target }} + + - name: Build Release + run: cargo build --locked --target=${{ matrix.platform.target }} ${{ matrix.platform.args }} --release + + - name: Rename binary + shell: bash + id: rename_binary + run: | + IFS='-' read -a arch <<< ${{ matrix.platform.target }} + suffix="" + if [[ "${{ matrix.platform.target }}" == *"musl"* ]]; then suffix="-static"; fi + binary_name=./target/${{ matrix.platform.target }}/release/cosmo-${arch}${suffix} + mv ./target/${{ matrix.platform.target }}/release/cosmo ${binary_name} + echo "binary_name=${binary_name}" >> $GITHUB_OUTPUT - # Upload binaries - - name: Upload cosmo x86_64 - id: upload-release-cosmo-x86_64 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload binary + uses: actions/upload-artifact@v3 with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: target/x86_64-unknown-linux-gnu/release/cosmo - asset_name: cosmo-linux-x86_64 - asset_content_type: application/octet-stream - - name: Upload static cosmo x86_64 - id: upload-release-static-cosmo-x86_64 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + name: binaries-${{ env.REGISTRY_TAG }} + path: ${{ steps.rename_binary.outputs.binary_name }} + if-no-files-found: error + retention-days: 1 + + create-release: + name: Create release + runs-on: ubuntu-latest + needs: + - build + - vendored_archive + steps: + - name: Download binaries + uses: actions/download-artifact@v3 with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: target/x86_64-unknown-linux-musl/release/cosmo - asset_name: cosmo-linux-x86_64-static - asset_content_type: application/octet-stream + name: binaries-${{ env.REGISTRY_TAG }} + path: /tmp/binaries + + - name: Release + uses: ncipollo/release-action@v1 + with: + name: ${{ env.REGISTRY_TAG }} + draft: true + tag: ${{ env.REGISTRY_TAG }} + artifacts: "/tmp/binaries/*" + body: | +
+ + Check out the [changelog](https://github.com/exein-io/cosmo-cli/blob/main/CHANGELOG.md) for details on all the changes and fixes. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index b7f1437..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Lint and Tests - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install toolchain with clippy available - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: clippy - - - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -Dwarnings - - - name: Run tests - uses: actions-rs/cargo@v1 - with: - command: test \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 29080bd..eeacf11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ rust-ini = "0.19.0" [features] default = [] -vendored-openssl = ['openssl/vendored'] # Statically include openssl +openssl-vendored = ['openssl/vendored'] # Statically include openssl [profile.release] lto = true # Enable Link Time Optimization diff --git a/Cross.toml b/Cross.toml deleted file mode 100644 index 93f0f75..0000000 --- a/Cross.toml +++ /dev/null @@ -1,7 +0,0 @@ -[target.x86_64-unknown-linux-gnu] -image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main" -pre-build = ["apt install -y libssl-dev"] - -[target.x86_64-unknown-linux-musl] -image = "ghcr.io/cross-rs/x86_64-unknown-linux-musl:main" -# pre-build = ["apt install -y "]