Skip to content

Update branch and event in CD workflow triggers #197

Update branch and event in CD workflow triggers

Update branch and event in CD workflow triggers #197

Workflow file for this run

name: CD
on:
push:
branches: [trigger]
tags: ["v*"]
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
actions: write
packages: write
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
ACTIONS_RUNTIME_TOKEN: dummy
CARGO_TERM_COLOR: always
jobs:
# Version bump and tag creation on main push
#
# On: Push to main
# Do: 1. Bump version using cargo-bump
# 2. Push to tag and changes to main
version-bump:
if: github.ref == 'refs/heads/trigger' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Rust
uses: actions-rs/toolchain@v1
- name: Configure git
run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
- name: Install cargo-bump
run: cargo install cargo-bump
- name: Bump version and create tag
run: |
cargo bump patch --git-tag
git commit -a --amend --no-edit
git push origin HEAD --tags
# Create draft release when tag is pushed
#
# On: Tag is pushed
# Do: 1. Create draft release
create-draft:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Draft Release
uses: softprops/action-gh-release@v2
with:
draft: true
generate_release_notes: true
# Build and upload artifacts when release is published (including pre-releases)
#
# On: Release is published
# Do: 1. Build artifacts for all platforms
# 2. Upload artifacts to release
build-artifacts:
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
target: x86_64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
steps:
- uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: ${{ matrix.target }}
override: true
profile: minimal
- name: Add x86_64-unknown-linux-musl target
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
rustup target add x86_64-unknown-linux-musl
sudo apt-get update && sudo apt-get install -y musl-tools
- name: Install Dependencies for musl Target
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev
- name: Build for target
run: |
cargo build \
-Z unstable-options \
--profile dev \
--artifact-dir bin \
--target ${{ matrix.target }}
- name: Zip artifacts
run: zip -r git-ai-${{ matrix.target }}.zip bin/git-*
- name: Upload artifacts
uses: softprops/action-gh-release@v2
with:
files: git-ai-*.zip
tag_name: ${{ github.event.release.tag_name }}
# Publish to crates.io when release is published
#
# On: Release is published
# Do: 1. Publish to crates.io
publish:
needs: build-artifacts
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rs/toolchain@v1
- name: Publish to crates.io
run: cargo publish --allow-dirty