webexmemebot/.gitea/workflows/release.yml

169 lines
5.8 KiB
YAML
Raw Normal View History

name: Release
on:
schedule:
- cron: "0 9 * * 0"
issue_comment:
types: [created]
jobs:
manual_trigger:
name: Manual Trigger Cleanup
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 }}"
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
outputs:
release_name: ${{ steps.get_next_version.outputs.tag }}
steps:
- name: Check out repository
uses: actions/checkout@v4.2.2
with:
fetch-depth: 0
- name: Changes since last tag
id: changes
run: |
rm -f .changes
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: 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"
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-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: |
2025-01-02 19:01:56 +01:00
curl -s -X POST \
-H "Authorization: token ${{ secrets.ACTIONS_TOKEN }}" \
-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"
2025-01-02 19:21:12 +01:00
build_docker:
name: Build Docker Images
needs: create_release
steps:
2025-01-02 19:47:33 +01:00
- name: Update Docker configuration
continue-on-error: true
run: |
mkdir -p /etc/default
mkdir -p /etc/docker
touch -a /etc/default/docker
touch -a /etc/docker/daemon.json
echo "DOCKER_OPTS=\"--insecure-registry ${{ vars.PACKAGES_REGISTRY_URL }}\"" >> /etc/default/docker
echo "{\"insecure-registries\": [\"${{ vars.PACKAGES_REGISTRY_URL }}\"]}" > /etc/docker/daemon.json
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.create_release.outputs.release_name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
2025-01-02 19:21:12 +01:00
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.PACKAGES_REGISTRY_URL }}
username: ${{ vars.ACTIONS_USERNAME }}
password: ${{ secrets.ACTIONS_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
2025-01-02 19:21:12 +01:00
username: ${{ vars.GHCR_USERNAME }}
2025-01-01 00:45:10 +01:00
password: ${{ secrets.GHCR_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
2025-01-02 19:21:12 +01:00
images: |
ghcr.io/${{ vars.GHCR_USERNAME }}/webexmemebot
${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}
tags: type=semver,pattern=v{{version}},value=${{ needs.create_release.outputs.release_name }}
# - name: Build and push images
# uses: docker/build-push-action@v5
# with:
# context: .
# push: true
# annotations: ${{ steps.meta.outputs.annotations }}
# labels: ${{ steps.meta.outputs.labels }}
# tags: ${{ steps.meta.outputs.tags }}
- name: Build images
run: |
dkrannotations=""
dkrlabels=""
dkrtags=""
for i in "${{ steps.meta.outputs.annotations }}"; do dkrannotations="$dkrannotations --annotation $i"; done
for i in "${{ steps.meta.outputs.labels }}"; do dkrlabels="$dkrlabels --label $i"; done
for i in "${{ steps.meta.outputs.tags }}"; do dkrtags="$dkrtags --tag $i"; done
bldcmd="docker buildx build $dkrannotations $dkrlabels $dkrtags ."
echo $bldcmd
$bldcmd
unset dkrannotations dkrlabels dkrtags bldcmd
- name: Push images
run: |
for i in "${{ steps.meta.outputs.tags }}"; do docker push "$i"; done
unset tags