Skip to content

ci: fix changelog subshell pipe issue, use bash array for loop #5

ci: fix changelog subshell pipe issue, use bash array for loop

ci: fix changelog subshell pipe issue, use bash array for loop #5

Workflow file for this run

name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
strategy:
fail-fast: false
matrix:
include:
- name: windows-x86_64
target: x86_64-pc-windows-msvc
os: windows-latest
lib: rustyjavac_native.dll
- name: linux-x86_64
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
lib: rustyjavac_native.so
- name: macos-x86_64
target: x86_64-apple-darwin
os: macos-latest
lib: rustyjavac_native.dylib
- name: macos-aarch64
target: aarch64-apple-darwin
os: macos-latest
lib: rustyjavac_native.dylib
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Rename artifact
shell: bash
run: |
src=$(find target/${{ matrix.target }}/release -maxdepth 1 -name "*rustyjavac_native*" \( -name "*.so" -o -name "*.dylib" -o -name "*.dll" \) | head -1)
if [ ! -f "$src" ]; then
echo "ERROR: built library not found. Listing release dir:"
ls -la target/${{ matrix.target }}/release/*.so target/${{ matrix.target }}/release/*.dylib target/${{ matrix.target }}/release/*.dll 2>/dev/null || true
exit 1
fi
echo "Found: $src"
cp "$src" ${{ matrix.lib }}
- name: Generate SHA-256
shell: bash
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
certutil -hashfile ${{ matrix.lib }} SHA256 | grep -E '^[a-fA-F0-9]{64}$' | tr '[:upper:]' '[:lower:]' > ${{ matrix.lib }}.sha256
else
shasum -a 256 ${{ matrix.lib }} | awk '{print $1}' > ${{ matrix.lib }}.sha256
fi
echo "sha256=$(cat ${{ matrix.lib }}.sha256)" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: |
${{ matrix.lib }}
${{ matrix.lib }}.sha256
if-no-files-found: error
changelog:
name: Generate changelog
runs-on: ubuntu-latest
outputs:
body: ${{ steps.changelog.outputs.body }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
shell: bash
run: |
set -e
TAG_NAME="${GITHUB_REF_NAME}"
PREV_TAG=$(git tag --sort=-creatordate | grep -v "^$TAG_NAME$" | head -1)
if [ -z "$PREV_TAG" ]; then
COMMITS=($(git log --pretty=format:"%s %h" --no-merges))
else
COMMITS=($(git log "$PREV_TAG..HEAD" --pretty=format:"%s %h" --no-merges))
fi
echo "## Changes" > /tmp/changelog.md
echo "" >> /tmp/changelog.md
if [ ${#COMMITS[@]} -eq 0 ]; then
echo "_no new commits since last tag_" >> /tmp/changelog.md
else
for line in "${COMMITS[@]}"; do
message="${line% *}"
hash="${line##* }"
category=""
case "$message" in
feat*) category="🚀 feat" ;;
fix*) category="🐛 fix" ;;
perf*) category="⚡ perf" ;;
refactor*) category="♻️ refactor" ;;
test*) category="✅ test" ;;
docs*) category="📝 docs" ;;
chore*) category="🔧 chore" ;;
ci*) category="👷 ci" ;;
*) category="📦 other" ;;
esac
clean_msg=$(echo "$message" | sed -E 's/^[a-z]+(\([^)]*\))?: ?//')
echo "- **$category**: $clean_msg (\`$hash\`)" >> /tmp/changelog.md
done
fi
{
echo "body<<EOF"
cat /tmp/changelog.md
echo "EOF"
} >> "$GITHUB_OUTPUT"
release:
name: Create GitHub Release
needs: [build, changelog]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: "*"
path: artifacts
- name: Show artifacts
run: ls -laR artifacts/
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
body: ${{ needs.changelog.outputs.body }}
files: |
artifacts/**/rustyjavac_native.dll
artifacts/**/rustyjavac_native.so
artifacts/**/rustyjavac_native.dylib
fail_on_unmatched_files: true
generate_release_notes: false