Skip to content

v0.2.1

v0.2.1 #3

Workflow file for this run

name: Release
run-name: ${{ github.ref_name }}
on:
push:
tags:
- 'v*.*.*'
- 'v*.*.*-*'
permissions:
contents: write
jobs:
checks:
name: Checks
runs-on: ubuntu-latest
outputs:
APP_NAME: ${{ steps.name.outputs.name }}
APP_VERSION: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get app name
id: name
shell: bash
run: |
APP_NAME=$(grep -m1 -oP '(?<=name = ")[^"]*' Cargo.toml)
echo "name=$APP_NAME"
echo "name=$APP_NAME" >> $GITHUB_OUTPUT
- name: Get app version
id: version
shell: bash
run: |
APP_VERSION=$(grep -m1 -oP '(?<=version = ")[^"]*' Cargo.toml)
echo "version=$APP_VERSION"
echo "version=$APP_VERSION" >> $GITHUB_OUTPUT
- name: Match version check
id: match_version_check
shell: bash
run: |
APP_VERSION="${{ steps.version.outputs.version }}"
TAG=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
if [[ $TAG == v* ]]; then
TAG=${TAG:1}
fi
echo "Extracted tag for comparison: $TAG"
if [[ $APP_VERSION != $TAG ]]; then
echo "ERROR: version in Cargo.toml ($APP_VERSION) does not match the pushed tag ($TAG)"
exit 1
fi
make_matrix:
runs-on: ubuntu-latest
needs: checks
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
env:
MATRIX_FILE: matrix.jsonc
steps:
- name: Clone repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- id: set-matrix
run: |
echo "matrix=$(grep -v '//' $MATRIX_FILE | jq -c '.')" >> "$GITHUB_OUTPUT"
ci:
name: CI
needs: [ checks, make_matrix ]
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{fromJson(needs.make_matrix.outputs.matrix)}}
max-parallel: 5
steps:
- name: Clone repo
uses: actions/checkout@v4
- name: Extract toolchain channel
id: extract_toolchain
shell: bash
run: |
TOOLCHAIN_CHANNEL=$(grep 'channel' rust-toolchain.toml | cut -d '"' -f 2)
echo "Toolchain channel: $TOOLCHAIN_CHANNEL"
echo "TOOLCHAIN_CHANNEL=$TOOLCHAIN_CHANNEL" >> $GITHUB_OUTPUT
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ steps.extract_toolchain.outputs.TOOLCHAIN_CHANNEL }}
- name: Setup just runner
uses: extractions/setup-just@v2
- name: Install cross-compilation tools
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- name: Build for release
run: cargo build --target ${{ matrix.target }} --release
- name: Test project
# Skip tests on FreeBSD, because testing are not supported by cross on FreeBSD.
# https://github.com/cross-rs/cross#supported-targets
if: ${{ !contains(matrix.target, 'freebsd') && !contains(matrix.target, 'aarch64-pc-windows-msvc') }}
run: cargo test --verbose
- name: Compress and archive
id: archive
shell: bash
run: |
mkdir -p _temp/release
FILENAMEBASE="${{ needs.checks.outputs.APP_NAME }}-${{ needs.checks.outputs.APP_VERSION }}-${{ matrix.target }}"
cp LICENSE.txt README.md CHANGELOG.md _temp/release/
if [[ "$RUNNER_OS" == "Windows" ]]; then
cp target/${{ matrix.target }}/release/exif_renamer.exe _temp/release/
cd _temp/release
7z a -tzip ../${FILENAMEBASE}.zip *
echo "archive_name=${FILENAMEBASE}.zip" >> $GITHUB_OUTPUT
echo "archive_path=_temp/${FILENAMEBASE}.zip" >> $GITHUB_OUTPUT
else
cp target/${{ matrix.target }}/release/exif_renamer _temp/release/
cd _temp/release
tar -czvf ../${FILENAMEBASE}.tar.gz * > /dev/null
echo "archive_name=${FILENAMEBASE}.tar.gz" >> $GITHUB_OUTPUT
echo "archive_path=_temp/${FILENAMEBASE}.tar.gz" >> $GITHUB_OUTPUT
fi
- name: Upload artifact
if: startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: ${{ steps.archive.outputs.archive_name }}
path: ${{ steps.archive.outputs.archive_path }}
if-no-files-found: error
retention-days: 1
compression-level: 0 # no compression
release:
name: Release
runs-on: ubuntu-latest
needs: ci
# Only run this job if the push event is a tag push
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release and upload assets
uses: softprops/action-gh-release@v2
with:
name: ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
body: |
Release notes for `${{ github.ref_name }}` are available here: https://github.com/pirafrank/rust_exif_renamer/blob/main/CHANGELOG.md
files: artifacts/**/*
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref, 'pre') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
# Note: drafts and prereleases cannot be set as latest.
make_latest: ${{ !contains(github.ref, 'pre') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc') }}
fail_on_unmatched_files: true
# no need to specify GITHUB_TOKEN here, it is automatically provided by GitHub Actions
publish:
name: Publish crate
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}