webexmemebot/.gitea/workflows/release.yml

203 lines
6.7 KiB
YAML
Raw Normal View History

name: Release
on:
schedule:
- cron: "0 9 * * 0"
issue_comment:
types: [created]
jobs:
check_manual_trigger:
runs-on: ubuntu-latest
steps:
- name: Log event metadata
run: |
echo "Issue: ${{ gitea.event.issue.number }}"
echo "Comment: ${{ gitea.event.comment.body }}"
echo "User: ${{ gitea.event.comment.user.login }}"
2025-01-01 01:40:25 +01:00
- name: Stop workflow if required conditions are not met
if: ${{ !contains(gitea.event.issue.number, '436') || !contains(gitea.event.comment.body, '/trigger-release') || !contains(gitea.event.comment.user.login, 'luke') }}
2025-01-01 01:40:25 +01:00
run: exit 1
- name: Delete issue comment
run: |
curl -X DELETE -H "Authorization: token ${{ gitea.token }}" "${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/issues/comments/${{ gitea.event.comment.id }}"
get_latest_tag:
name: Get latest tag
runs-on: ubuntu-latest
needs: check_manual_trigger
outputs:
latesttag: ${{ steps.latesttag.outputs.latesttag }}
steps:
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 0
- name: Get latest tag
id: latesttag
run: |
LATESTTAG=$(git describe --tags --abbrev=0)
2025-01-01 02:17:01 +01:00
echo "latesttag=$LATESTTAG" >> "$GITEA_OUTPUT"
2025-01-01 05:03:35 +01:00
# test:
# name: Unit Test
# needs: get_latest_tag
# uses: https://git.tainton.uk/public/webexmemebot/.gitea/workflows/ci.yml@${{ needs.get_latest_tag.outputs.latesttag }}
# continue-on-error: true
create_release:
name: Create Release
runs-on: ubuntu-latest
# needs: test
outputs:
release_name: ${{ steps.tag_version.outputs.new_tag }}
success: ${{ steps.set_flag.outputs.success }}
2025-01-01 03:11:01 +01:00
# srvurl: ${{ steps.set_srvurl.outputs.srvurl }}
steps:
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 0
- name: Changes since last tag
id: changes
run: |
2025-01-01 05:10:45 +01:00
rm -f .changes .changes_feat .changes_fix .changes_dep .changes_other
2025-01-01 05:03:35 +01:00
git log $(git describe --tags --abbrev=0)..HEAD --no-merges --oneline >> .changes
2025-01-01 05:10:45 +01:00
cat .changes
2025-01-01 05:03:35 +01:00
if [[ -z $(grep '[^[:space:]]' .changes) ]] ; then
2025-01-01 05:10:45 +01:00
echo "changes=false"
2025-01-01 03:11:01 +01:00
echo "changes=false" >> "$GITEA_OUTPUT"
else
2025-01-01 05:10:45 +01:00
echo "changes=true"
2025-01-01 03:11:01 +01:00
echo "changes=true" >> "$GITEA_OUTPUT"
2025-01-01 05:10:45 +01:00
grep -i "feat" .changes >> .changes_feat
grep -i "fix" .changes >> .changes_fix
grep -i "dependencies" .changes >> .changes_dep
grep -i "other" .changes >> .changes_other
2025-01-01 03:11:01 +01:00
fi
2025-01-01 05:03:35 +01:00
- name: Cancel if no changes
if: steps.changes.outputs.changes == 'false'
run: exit 1
2025-01-01 03:11:01 +01:00
- name: Create changelog
id: create_changelog
2025-01-01 05:03:35 +01:00
if: steps.changes.outputs.changes == 'true'
2025-01-01 03:11:01 +01:00
run: |
2025-01-01 05:10:45 +01:00
rm -f .changelog
2025-01-01 05:03:35 +01:00
if [[ -z $(grep '[^[:space:]]' .changes_feat) ]] ; then
2025-01-01 03:39:40 +01:00
printf "## 🚀 Features" > .changelog
cat .changes_feat >> .changelog
2025-01-01 05:03:35 +01:00
fi
if [[ -z $(grep '[^[:space:]]' .changes_fix) ]] ; then
printf "## 🐛 Bug Fixes" >> .changelog
2025-01-01 03:39:40 +01:00
cat .changes_fix >> .changelog
2025-01-01 05:03:35 +01:00
fi
if [[ -z $(grep '[^[:space:]]' .changes_dep) ]] ; then
printf "## 📦 Dependencies" >> .changelog
2025-01-01 03:39:40 +01:00
cat .changes_dep >> .changelog
2025-01-01 05:03:35 +01:00
fi
if [[ -z $(grep '[^[:space:]]' .changes_other) ]] ; then
printf "## 💬 Other" >> .changelog
2025-01-01 03:39:40 +01:00
cat .changes_other >> .changelog
2025-01-01 03:11:01 +01:00
fi
2025-01-01 02:54:00 +01:00
- name: Set server URL
id: set_srvurl
run: |
SRVURL=$(echo "${{ gitea.server_url }}" | sed 's/https:\/\/\(.*\)/\1/')
echo "srvurl=$SRVURL" >> "$GITEA_OUTPUT"
- name: Get next version
uses: TriPSs/conventional-changelog-action@v6
id: get_next_version
with:
2025-01-01 02:54:00 +01:00
git-url: ${{ steps.set_srvurl.outputs.srvurl }}
github-token: ${{ gitea.token }}
skip-commit: true
release-count: 1
output-file: false
create-summary: true
skip-on-empty: true
skip-version-file: true
skip-tag: true
- name: Create release
id: create_release
uses: akkuman/gitea-release-action@v1
env:
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
with:
tag: ${{ steps.get_next_version.outputs.tag }}
name: ${{ steps.get_next_version.outputs.tag }}
2025-01-01 03:39:40 +01:00
body_path: .changelog
- name: Set success/fail flag
id: set_flag
if: steps.changes.outputs.changes == 'true'
run: if test "${{ steps.changes.outputs.changes }}" = "true"; then echo "success=true" >> "$GITHUB_OUTPUT"; else echo "success=false" >> "$GITHUB_OUTPUT"; fi
create_docker:
name: Create Docker Image
needs: create_release
if: ${{ needs.create_release.outputs.success == 'true' }}
outputs:
success: ${{ steps.set_flag.outputs.success }}
with:
release: ${{ needs.create_release.outputs.release_name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.release }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: git.tainton.uk
username: ${{ gitea.actor }}
password: ${{ gitea.token }}
2025-01-01 00:45:10 +01:00
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: luketainton
password: ${{ secrets.GHCR_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
git.tainton.uk/${{ gitea.repository }}
2025-01-01 00:45:10 +01:00
ghcr.io/luketainton/webexmemebot
tags: |
type=semver,pattern=v{{version}},value=${{ inputs.release }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
labels: ${{ steps.meta.outputs.labels }}
tags: |
git.tainton.uk/${{ gitea.repository }}:latest
git.tainton.uk/${{ gitea.repository }}:${{ inputs.release }}
2025-01-01 00:45:10 +01:00
ghcr.io/luketainton/webexmemebot:latest
ghcr.io/luketainton/webexmemebot:${{ inputs.release }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
2025-01-01 00:45:10 +01:00
subject-name: ghcr.io/luketainton/webexmemebot
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Set success flag
id: set_flag
run: echo "success=true" >> "$GITHUB_OUTPUT"