webexmemebot/.gitea/workflows/release.yml

234 lines
7.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.1.7
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"
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.1.7
with:
fetch-depth: 0
- name: Changes since last tag
id: changes
run: |
CHANGES=$(git log $(git describe --tags --abbrev=0)..HEAD --no-merges --oneline)
echo "$CHANGES"
2025-01-01 03:11:01 +01:00
$CHANGES_FEAT=$(echo "$CHANGES" | grep -i "feat")
$CHANGES_FIX=$(echo "$CHANGES" | grep -i "fix")
$CHANGES_DEP=$(echo "$CHANGES" | grep -i "dependencies")
$CHANGES_OTHER=$(echo "$CHANGES" | grep -i "other")
if [ -z "$CHANGES" ]
then
echo "changes=false" >> "$GITEA_OUTPUT"
else
echo "changes=true" >> "$GITEA_OUTPUT"
2025-01-01 03:39:40 +01:00
echo $CHANGES_FEAT" >> .changes_feat
echo $CHANGES_FIX" >> .changes_fix
echo $CHANGES_DEP" >> .changes_dep
echo $CHANGES_OTHER" >> .changes_other
2025-01-01 03:11:01 +01:00
fi
- name: Create changelog
id: create_changelog
run: |
if test "${{ steps.changes.outputs.changes }}" = "true"
then
2025-01-01 03:39:40 +01:00
printf "## 🚀 Features" > .changelog
cat .changes_feat >> .changelog
printf "\n\n## 🐛 Bug Fixes" >> .changelog
cat .changes_fix >> .changelog
printf "\n\n## 📦 Dependencies" >> .changelog
cat .changes_dep >> .changelog
printf "\n\n## 💬 Other" >> .changelog
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: Bump version and push tag
# id: tag_version
# if: steps.changes.outputs.changes == 'true'
# uses: mathieudutour/github-tag-action@v6.2
# with:
# github_token: ${{ gitea.token }}
# default_bump: minor
# # default_bump: false
2025-01-01 03:11:01 +01:00
# - name: Build Changelog
# uses: mikepenz/release-changelog-builder-action@v4
# id: build_changelog
# env:
# GITHUB_TOKEN: ${{ gitea.token }}
# with:
# platform: "gitea"
# configurationJson: |
# {
# "pr_template": "- #{{TITLE}} ([##{{NUMBER}}](#{{URL}}))",
# "empty_template": "- no changes",
# "categories": [
# {
# "title": "## 💬 Other",
# "labels": ["type/other"]
# },
# {
# "title": "## 📦 Dependencies",
# "labels": ["type/dependencies"]
# },
# {
# "title": "## 🚀 Features",
# "labels": ["type/feature"]
# },
# {
# "title": "## 🐛 Bug Fixes",
# "labels": ["type/bugfix"]
# },
# ]
# }
- 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"