Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add build automation, add optional rustls compilation #13

Merged
merged 40 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
50 changes: 0 additions & 50 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,3 @@ autolabeler:
- label: breaking
title:
- '/^[a-z]+(\(.*\))?\!\:/'
# ------------------------------------ RELEASE CONFIGURATION ------------------------------------ #
category-template: "### $TITLE"
change-template: "- $TITLE by @$AUTHOR in [#$NUMBER]($URL)"
replacers:
# remove conventional commit tag & scope from change list
- search: '/- [a-z]+(\(.*\))?(\!)?\: /g'
replace: "- "
template: |
## What's Changed

$CHANGES

**Full Changelog:** [`$PREVIOUS_TAG...v$RESOLVED_VERSION`](https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION)
categories:
- title: ⚠️ Breaking Changes
labels:
- breaking
- title: ✨ New Features
labels:
- enhancement
- title: 🐞 Bug Fixes
labels:
- fix
- title: 🏎️ Performance Improvements
labels:
- performance
- title: 📚 Documentation
labels:
- documentation
- title: 🏗️ Testing
labels:
- test
- title: ⚙️ Automation
labels:
- ci
- title: 🛠 Builds
labels:
- build
- title: 💎 Code Style
labels:
- style
- title: 📦 Refactorings
labels:
- refactor
- title: ♻️ Chores
labels:
- chore
- title: 🗑 Reverts
labels:
- revert
36 changes: 36 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
changelog:
exclude:
labels:
- ignore for release
categories:
- title: 🚨 Breaking changes
labels:
- breaking
- title: ✨ New features
labels:
- enhancement
- title: 🚀 Performance
labels:
- performance
- title: 🐛 Bug fixes
labels:
- bug
- fix
- title: 📝 Documentation
labels:
- documentation
- title: 🧪 Tests
labels:
- test
- title: ⬆️ Dependencies
labels:
- dependencies
- title: 🤖 CI
labels:
- ci
- title: 🏗️ Refactor
labels:
- refactor
- title: 🤷🏻 Other changes
labels:
- "*"
115 changes: 115 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Build
on:
push:
branches:
- main
pull_request:

jobs:
metadata:
name: Check if version changed
runs-on: ubuntu-latest
outputs:
optimize-build: ${{ github.event_name == 'push' }}
release: ${{ github.event_name == 'push' && github.repository == 'Quantco/pixi-pack' && steps.version-metadata.outputs.changed == 'true' }}
version: ${{ steps.version-metadata.outputs.newVersion }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- uses: Quantco/ui-actions/version-metadata@a0653e9fc0ee3c4be9f7cc88e509e40536e9f3c1
id: version-metadata
with:
file: ./Cargo.toml
token: ${{ secrets.GITHUB_TOKEN }}
version-extraction-override: 'regex:version = "(.*)"'

build:
name: Build Binary
runs-on: ${{ matrix.os }}
needs: [metadata]
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-unknown-linux-musl
os: ubuntu-latest-arm-4core
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest-arm-4core
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-13
env:
# These are some environment variables that configure the build so that the binary size is reduced.
# Inspiration was taken from this blog: https://arusahni.net/blog/2020/03/optimizing-rust-binary-size.html
# They only enable it on main and releases.

# Enable Link Time Optimization (LTO) for our release builds. This increases link time but drastically reduces
# binary size.
CARGO_PROFILE_RELEASE_LTO: ${{ needs.metadata.outputs.optimize-build }}

# Use a single code gen unit. This effectively disables parallel linking but ensures that everything is linked
# together in a single unit which reduces the file-size at the cost of link time.
# Default for a release build is 16
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: ${{ needs.metadata.outputs.optimize-build && 1 || 16 }}

# Strip the binaries. This reduces the filesize of the final release.
pavelzw marked this conversation as resolved.
Show resolved Hide resolved
CARGO_PROFILE_RELEASE_STRIP: ${{ needs.metadata.outputs.optimize-build && 'symbols' || 'false' }}

# Optimize the binary for size. This reduces the filesize at the cost of a slower binary.
CARGO_PROFILE_OPT_LEVEL: ${{ needs.metadata.outputs.optimize-build && 's' || '0' }}
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up pixi
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
with:
activate-environment: true

- name: Rust cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
with:
key: build-${{ matrix.target }}-${{ needs.metadata.outputs.optimize-build }}

- name: Build
run: |
pixi run build --color always${{ endsWith(matrix.target, 'musl') && ' --no-default-features --features rustls-tls' || '' }}
mv target/release/pixi-pack${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }} pixi-pack-${{ matrix.target }}${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }}

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: pixi-pack-${{ matrix.target }}
delsner marked this conversation as resolved.
Show resolved Hide resolved
path: pixi-pack-${{ matrix.target }}${{ endsWith(matrix.target, 'windows-msvc') && '.exe' || '' }}
if-no-files-found: error

release:
name: Create Release
needs: [metadata, build]
if: needs.metadata.outputs.release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: pixi-pack-*
merge-multiple: true
- name: Push v${{ needs.metadata.outputs.version }} tag
run: |
git tag v${{ needs.metadata.outputs.version }}
git push origin v${{ needs.metadata.outputs.version }}
- name: Create Release
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87
with:
generate_release_notes: true
tag_name: v${{ needs.metadata.outputs.version }}
draft: true
delsner marked this conversation as resolved.
Show resolved Hide resolved
files: pixi-pack-*
58 changes: 58 additions & 0 deletions .github/workflows/chore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Chore
on:
pull_request:
branches: [main]
types: [opened, reopened, edited, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-pr-title:
name: Check PR Title
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Check valid conventional commit message
id: lint
uses: amannn/action-semantic-pull-request@cfb60706e18bc85e8aec535e3c577abe8f70378e
with:
subjectPattern: ^[A-Za-z].+[^. ]$ # subject must start with letter and may not end with a dot/space
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Post comment about invalid PR title
if: failure()
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31
with:
header: conventional-commit-pr-title
message: |
Thank you for opening this pull request! 👋🏼

This repository requires pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.

<details><summary><b>Details</b></summary>

```
${{ steps.lint.outputs.error_message }}
```

</details>

- name: Delete comment about invalid PR title
if: success()
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31
with:
header: conventional-commit-pr-title
delete: true

- name: Assign labels
uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348
with:
disable-releaser: true
disable-autolabeler: false
env:
GITHUB_TOKEN: ${{ github.token }}
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ jobs:
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os:
- ubuntu-latest
- ubuntu-latest-arm-4core
- windows-latest
- macos-latest
- macos-13
steps:
- name: Checkout branch
uses: actions/checkout@v4
Expand All @@ -39,8 +45,10 @@ jobs:
fetch-depth: 0
- name: Set up pixi
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
with:
activate-environment: true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swatinem/rust-cache prints some warnings/errors when the rust toolchain is not available

- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
with:
key: tests
- name: Run test
run: pixi run test
run: pixi run test --color always${{ startsWith(matrix.os, 'ubuntu') && ' --no-default-features --features rustls-tls' || '' }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: ^env/
exclude: (^env/|.pixi/)
repos:
- repo: local
hooks:
Expand Down
Loading