webexmemebot/.gitea/workflows/release.yml

252 lines
8.6 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
if: ${{ gitea.event_name == 'issue_comment' }}
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_last_tag:
# name: Get last tag
# runs-on: ubuntu-latest
# needs: check_manual_trigger
# outputs:
# last_tag: ${{ steps.last_tag.outputs.last_tag }}
# steps:
# - uses: actions/checkout@v4.2.2
# with:
# fetch-depth: 0
# - name: Get last tag
# id: last_tag
# run: |
# LASTTAG=$(git describe --tags --abbrev=0)
# echo "last_tag=$LASTTAG" >> "$GITEA_OUTPUT"
2025-01-01 05:03:35 +01:00
# test:
# name: Unit Test
# uses: https://git.tainton.uk/public/webexmemebot/.gitea/workflows/ci.yml@main
2025-01-01 05:03:35 +01:00
# continue-on-error: true
create_release:
name: Create Release
runs-on: ubuntu-latest
# needs: test
# needs: get_last_tag
outputs:
release_name: ${{ steps.tag_version.outputs.new_tag }}
success: ${{ steps.set_flag.outputs.success }}
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-02 18:25:18 +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-02 18:18:19 +01:00
- name: Upload changelog file
2025-01-02 18:25:18 +01:00
uses: actions/upload-artifact@v3
2025-01-02 18:18:19 +01:00
with:
name: changelog-file
path: ./.changes
include-hidden-files: true
- name: Check for changes
run: |
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-02 18:25:18 +01:00
grep -i "feat" .changes >> .changes_feat || true
grep -i "fix" .changes >> .changes_fix || true
grep -i "dependencies" .changes >> .changes_dep || true
grep -i "other" .changes >> .changes_other || true
2025-01-01 03:11:01 +01:00
fi
2025-01-01 05:03:35 +01:00
- name: Cancel if no changes
2025-01-02 18:45:50 +01:00
if: steps.changes.outputs.changes == 'false'
2025-01-01 05:03:35 +01:00
run: exit 1
2025-01-02 18:44:25 +01:00
# - name: Create changelog
# id: create_changelog
# if: steps.changes.outputs.changes == true
# run: |
# rm -f .changelog
# if [[ -z $(grep '[^[:space:]]' .changes_feat) ]] ; then
# printf "## 🚀 Features" > .changelog
# cat .changes_feat >> .changelog
# fi
# if [[ -z $(grep '[^[:space:]]' .changes_fix) ]] ; then
# printf "## 🐛 Bug Fixes" >> .changelog
# cat .changes_fix >> .changelog
# fi
# if [[ -z $(grep '[^[:space:]]' .changes_dep) ]] ; then
# printf "## 📦 Dependencies" >> .changelog
# cat .changes_dep >> .changelog
# fi
# if [[ -z $(grep '[^[:space:]]' .changes_other) ]] ; then
# printf "## 💬 Other" >> .changelog
# cat .changes_other >> .changelog
# 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
run: |
curl -X POST \
-u "${{ vars.PACKAGES_REGISTRY_USERNAME }}:${{ vars.PACKAGES_REGISTRY_PASSWORD }}" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{\"tag_name\": \"${{ steps.get_next_version.outputs.tag }}\", \"name\": \"${{ steps.get_next_version.outputs.tag }}\", \"body\": \"${{ steps.get_next_version.outputs.changelog }}\"}" \
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases"
# - 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 }}
# # body_path: .changelog
# body: ${{ steps.get_next_version.outputs.changelog }}
- name: Set success/fail flag
id: set_flag
if: steps.changes.outputs.changes == 'true'
2025-01-02 18:18:19 +01:00
run: if test "${{ steps.changes.outputs.changes }}" = "true"; then echo "success=true" >> "$GITEA_OUTPUT"; else echo "success=false" >> "$GITEA_OUTPUT"; fi
2025-01-02 18:44:25 +01:00
build_docker_ghcr:
name: Build GHCR Docker Images
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
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:
2025-01-02 18:44:25 +01:00
images: ghcr.io/luketainton/webexmemebot
tags: type=semver,pattern=v{{version}},value=${{ inputs.release }}
- name: Build and push images
id: build_push
uses: docker/build-push-action@v6
with:
context: .
push: true
labels: ${{ steps.meta.outputs.labels }}
tags: |
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
2025-01-02 18:44:25 +01:00
subject-digest: ${{ steps.build_push.outputs.digest }}
push-to-registry: true
- name: Set success flag
id: set_flag
2025-01-02 18:18:19 +01:00
run: echo "success=true" >> "$GITEA_OUTPUT"
2025-01-02 18:44:25 +01:00
build_docker_gitea:
name: Build Gitea Docker Images
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: ${{ vars.PACKAGES_REGISTRY_URL }}
username: ${{ vars.PACKAGES_REGISTRY_USERNAME }}
password: ${{ vars.PACKAGES_REGISTRY_PASSWORD }}
- name: Build Gitea image(s)
uses: docker/build-push-action@v6
with:
context: .
push: false
labels: ${{ steps.meta.outputs.labels }}
tags: |
${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}:latest
${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}:${{ inputs.release }}
- name: Push Gitea image(s)
run:
docker push ${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}:latest ${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}:${{ inputs.release }}
- name: Set success flag
id: set_flag
run: echo "success=true" >> "$GITEA_OUTPUT"