185 lines
6.0 KiB
YAML
185 lines
6.0 KiB
YAML
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 }}"
|
|
|
|
- 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') }}
|
|
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: |
|
|
git checkout main
|
|
git fetch --tags
|
|
LATESTTAG=$(git -C ${{ gitea.workspace }} describe --tags --abbrev=0)
|
|
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 }}
|
|
|
|
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 }}
|
|
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"
|
|
if [ -z "$CHANGES" ]; then echo "changes=false" >> "$GITEA_OUTPUT"; else echo "changes=true" >> "$GITEA_OUTPUT"; fi
|
|
|
|
- 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
|
|
|
|
- name: Build Changelog
|
|
uses: mikepenz/release-changelog-builder-action@v4
|
|
id: build_changelog
|
|
env:
|
|
GITHUB_TOKEN: ${{ gitea.token }}
|
|
with:
|
|
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.tag_version.outputs.new_tag }}
|
|
name: ${{ steps.tag_version.outputs.new_tag }}
|
|
body: ${{ steps.build_changelog.outputs.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 }}
|
|
|
|
- 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 }}
|
|
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 }}
|
|
ghcr.io/luketainton/webexmemebot:latest
|
|
ghcr.io/luketainton/webexmemebot:${{ inputs.release }}
|
|
|
|
- name: Generate artifact attestation
|
|
uses: actions/attest-build-provenance@v2
|
|
with:
|
|
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"
|