Release Piper Action #43
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 Piper Action | |
on: | |
workflow_dispatch: # trigger release manually | |
schedule: | |
- cron: '0 9 * * 1' # at 9 am every Monday | |
jobs: | |
check_if_should_run: | |
name: Check if should run | |
runs-on: ubuntu-latest | |
outputs: | |
should_run: ${{ steps.should_run.outputs.should_run || steps.manual_trigger.outputs.should_run }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get tags | |
run: git fetch --tags --prune --unshallow | |
- name: Get latest release tag | |
id: latest_tag | |
run: echo "latest_release_tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT" | |
# For scheduled runs check if there has been a commit since last release | |
- id: should_run | |
if: ${{ github.event_name == 'schedule' }} | |
name: Check latest commits | |
run: | | |
if [[ -n $(git log ${{ steps.latest_tag.outputs.latest_release_tag }}..HEAD --format=%H --max-count=5) ]] | |
then | |
echo "should_run=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "No commits since last release. Release will be skipped" | |
fi | |
# For manual release trigger. Release will be created even if there has been no commits since last release | |
- id: manual_trigger | |
if: ${{ github.event_name == 'workflow_dispatch' }} | |
run: echo "should_run=true" >> "$GITHUB_OUTPUT" | |
release: | |
name: Release | |
needs: check_if_should_run | |
if: ${{ needs.check_if_should_run.outputs.should_run == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Increment version | |
id: version | |
uses: reecetech/version-increment@2024.4.4 | |
with: | |
scheme: semver | |
increment: minor | |
- name: Create release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ steps.version.outputs.v-version }} | |
generate_release_notes: true | |
make_latest: true | |
post: | |
name: Post Action | |
runs-on: ubuntu-latest | |
needs: [release] | |
if: always() | |
steps: | |
# Check status of the worklfow | |
- uses: martialonline/workflow-status@v4 | |
id: check | |
# This step expects base64 encoded JSON object as below: | |
# { | |
# "smtp_url": "smtp+starttls://user:password@server:port", | |
# "smtp_mail_from": "from@mail.example", | |
# "smtp_mail_rcpt": "to@mail.example", | |
# } | |
- name: Decode SMTP secrets and set them in GITHUB_ENV | |
id: smtp_secrets | |
if: steps.check.outputs.status == 'failure' || steps.check.outputs.status == 'cancelled' | |
run: > | |
echo "${{ secrets.SMTP_CONFIG }}" | | |
base64 --decode | | |
jq -r 'to_entries[] | "\(.key)=\(.value)"' | | |
while read line; do | |
echo "$line" >> $GITHUB_ENV; echo "::add-mask::${line#*=}"; | |
done | |
- name: Notify Piper team on failure or cancelled | |
if: steps.smtp_secrets.conclusion == 'success' | |
uses: dawidd6/action-send-mail@v3 | |
with: | |
connection_url: ${{ env.smtp_url }} | |
subject: Workflow failure in ${{ github.repository }} | |
priority: high | |
to: ${{ env.smtp_mail_rcpt }} | |
from: Piper on GitHub <${{ env.smtp_mail_from }}> | |
body: | | |
Workflow '${{ github.workflow }}' has a job with status '${{ steps.check.outputs.status }}'. | |
Workflow link: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |