Skip to content

Commit

Permalink
ci: refac actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jun 1, 2024
1 parent 3d0cab1 commit 89c8a2c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
66 changes: 54 additions & 12 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ concurrency:
cancel-in-progress: true

jobs:
release:
if: "!startsWith(github.event.head_commit.message, 'ci(bump):')"
setup:
runs-on: ubuntu-latest
outputs:
prerelease: ${{ steps.set-prerelease.outputs.prerelease }}

steps:
- name: Checkout code
Expand All @@ -23,7 +24,7 @@ jobs:
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Check for pre-release configuration
id: prerelease
id: set-prerelease
run: |
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "prerelease=nightly" >> $GITHUB_OUTPUT
Expand All @@ -32,48 +33,89 @@ jobs:
else
echo "prerelease=false" >> $GITHUB_OUTPUT
changelog:
runs-on: ubuntu-latest
needs: setup
outputs:
version: ${{ steps.save-outputs.outputs.version }}
changelog: ${{ steps.save-outputs.outputs.changelog }}
commit_message: ${{ steps.save-outputs.outputs.commit_message }}
branch: ${{ steps.save-outputs.outputs.branch }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- id: cz
name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
changelog_increment_filename: body.md
prerelease: ${{ steps.prerelease.outputs.prerelease }}
prerelease: ${{ needs.setup.outputs.prerelease }}

- name: Save outputs
id: vars
id: save-outputs
run: |
version=${{ steps.cz.outputs.version }}
changelog=$(cat body.md)
commit_message="ci(bump): release ${version}"
branch="release-${{ steps.vars.outputs.version }}"
branch="release-${{ steps.cz.outputs.version }}"
echo "version=${version}" >> $GITHUB_OUTPUT
echo "changelog=${changelog}" >> $GITHUB_OUTPUT
echo "commit_message=${commit_message}" >> $GITHUB_OUTPUT
echo "branch=${branch}" >> $GITHUB_OUTPUT
create_pr:
runs-on: ubuntu-latest
needs: changelog

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
commit-message: ${{ steps.vars.outputs.commit_message }}
title: Release ${{ steps.vars.outputs.version }}
commit-message: ${{ needs.changelog.outputs.commit_message }}
title: Release ${{ needs.changelog.outputs.version }}
body: |
${{ steps.vars.outputs.changelog }}
branch: release-${{ steps.vars.outputs.version }}
${{ needs.changelog.outputs.changelog }}
branch: ${{ needs.changelog.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
release:
runs-on: ubuntu-latest
needs: changelog
if: github.ref == 'refs/heads/release'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Release
if: ${{ github.ref == 'refs/heads/release' }}
uses: softprops/action-gh-release@v1
with:
body_path: body.md
tag_name: ${{ env.REVISION }}
tag_name: ${{ needs.changelog.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

notify:
runs-on: ubuntu-latest
if: failure()

steps:
- name: Error Notification
run: |-
echo "An error occurred during the release process"
# Optionally, send a notification to Slack or email
4 changes: 2 additions & 2 deletions .github/workflows/update_deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ env:
jobs:
update:
name: Update Dependencies
runs-on: buildjet-4vcpu-ubuntu-2204
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
pr:
name: Create or Update Pull Request
needs: update
runs-on: buildjet-4vcpu-ubuntu-2204
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand Down

0 comments on commit 89c8a2c

Please sign in to comment.