fix: release process #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "The version to release" | |
type: string | |
permissions: | |
contents: write | |
pull-requests: read | |
statuses: write | |
packages: write | |
jobs: | |
release: | |
name: Release | |
runs-on: "ubuntu-latest" | |
timeout-minutes: 15 | |
if: "!startsWith(github.event.head_commit.message, '[Release]')" | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
with: | |
fetch-depth: 0 | |
- uses: jdx/mise-action@v2 | |
with: | |
experimental: true | |
version: 2024.11.8 | |
- name: Restore Cache | |
uses: actions/cache@v4 | |
id: mix-cache | |
with: | |
path: | | |
deps | |
_build | |
key: mix-${{ hashFiles('mix.lock') }} | |
- run: mix deps.get | |
- name: Check if there are releasable changes | |
id: is-releasable | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
bumped_output=$(git cliff --bump --unreleased) | |
changelog_content=$(cat CHANGELOG.md) | |
bumped_hash=$(echo -n "$bumped_output" | shasum -a 256 | awk '{print $1}') | |
changelog_hash=$(echo -n "$changelog_content" | shasum -a 256 | awk '{print $1}') | |
if [ "$bumped_hash" != "$changelog_hash" ]; then | |
echo "A new version should be released" | |
echo "Bumped: $bumped_hash" | |
echo "Changelog: $changelog_hash" | |
echo "should-release=true" >> $GITHUB_ENV | |
else | |
echo "No new version should be released" | |
echo "Bumped: $bumped_hash" | |
echo "Changelog: $changelog_hash" | |
echo "should-release=false" >> $GITHUB_ENV | |
fi | |
- name: Get next version | |
id: next-version | |
if: env.should-release == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: echo "NEXT_VERSION=$(git cliff --bumped-version)" >> "$GITHUB_OUTPUT" | |
- name: Update CHANGELOG.md | |
if: env.should-release == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: git cliff --bump -o CHANGELOG.md | |
- name: Commit changes | |
id: auto-commit-action | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
if: env.should-release == 'true' | |
with: | |
commit_options: "--allow-empty" | |
tagging_message: ${{ steps.next-version.outputs.NEXT_VERSION }} | |
skip_dirty_check: true | |
commit_message: "[Release] lightning_css ${{ steps.next-version.outputs.NEXT_VERSION }}" | |
- name: Get release notes | |
id: release-notes | |
if: env.should-release == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
echo "RELEASE_NOTES<<EOF" >> "$GITHUB_OUTPUT" | |
git cliff --latest >> "$GITHUB_OUTPUT" | |
echo "EOF" >> "$GITHUB_OUTPUT" | |
- name: Update version in mix.exs | |
if: env.should-release == 'true' | |
run: | | |
sed -i 's/@version ".*"/@version "${{ steps.next-version.outputs.NEXT_VERSION }}"/' mix.exs | |
git add mix.exs | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
if: env.should-release == 'true' | |
with: | |
draft: false | |
repository: tuist/lightning_css | |
name: ${{ steps.next-version.outputs.NEXT_VERSION }} | |
tag_name: ${{ steps.next-version.outputs.NEXT_VERSION }} | |
body: ${{ steps.release-notes.outputs.RELEASE_NOTES }} | |
target_commitish: ${{ steps.auto-commit-action.outputs.commit_hash }} | |
- name: Publish package to Hex | |
if: env.should-release == 'true' | |
env: | |
HEX_API_KEY: ${{ secrets.HEX_PM_TOKEN }} | |
run: mix hex.publish --yes |