Skip to content

Improve release action #104

Improve release action

Improve release action #104

Workflow file for this run

name: Release
on:
push:
branches:
- main
tags:
- "v*"
permissions:
contents: write
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.ref }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy, rustfmt
- name: Install XCB dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
- name: Build
run: cargo build --release
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: filectrl-${{ matrix.os }}
path: target/release/filectrl
release:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
steps:
# We need to checkout the code in order to delete the "main" tag
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.ref }}
# Only delete the tag if it exists and we're on main branch
- name: Delete any existing "main" tag
if: github.ref == 'refs/heads/main'
run: |
git push --delete origin refs/tags/main || true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
# Prepare files with correct names for release
- name: Prepare release assets
run: |
mkdir -p release-assets
cp artifacts/filectrl-ubuntu-latest/filectrl release-assets/filectrl-linux
cp artifacts/filectrl-macos-latest/filectrl release-assets/filectrl-macos
# GitHub releases require a tag, so this step will auto-create a tag for the "main" release.
# We delete the 'main' tag in advance (above), so that step will create a new one that points
# to the latest revision on the main branch
- name: Create GitHub release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref == 'refs/heads/main' && 'main' || github.ref_name }}
name: ${{ github.ref == 'refs/heads/main' && 'main' || github.ref_name }}
body: ${{ github.ref == 'refs/heads/main' && 'Latest build from main branch' || '' }}
files: |
release-assets/filectrl-linux
release-assets/filectrl-macos