ci(gitea): migrate release workflow
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
name: Build Docker Image - Latest
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: docker.lechner-systems.at
|
||||
IMAGE_NAME: lechnersystems/portfolio
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
code: read
|
||||
releases: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Use Node.js v24.14.0
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '24.14.0'
|
||||
|
||||
- name: Set build version
|
||||
run: npm run version:set
|
||||
|
||||
- name: Read version from package.json
|
||||
id: version
|
||||
run: |
|
||||
version=$(node -p 'require("./package.json").version')
|
||||
docker_tag=${version//+/-}
|
||||
revision=${GITEA_RUN_ATTEMPT}
|
||||
echo "value=$version" >> "$GITHUB_OUTPUT"
|
||||
echo "docker_tag=$docker_tag" >> "$GITHUB_OUTPUT"
|
||||
echo "revision=$revision" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Build and push latest image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
provenance: false
|
||||
build-args: |
|
||||
APP_VERSION=${{ steps.version.outputs.value }}
|
||||
VCS_REF=${{ steps.version.outputs.revision }}
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
|
||||
- name: Create Gitea release
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
RELEASE_TAG: v${{ steps.version.outputs.docker_tag }}
|
||||
run: |
|
||||
api_url="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases"
|
||||
# ponytail: 50 recent releases cover normal reruns; paginate if old releases are rebuilt.
|
||||
releases="$(curl --fail-with-body --silent --show-error \
|
||||
--header "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${api_url}?limit=50")"
|
||||
previous_tag="$(printf '%s' "$releases" | jq -r \
|
||||
--arg tag "$RELEASE_TAG" \
|
||||
'[.[] | select(.draft == false and .tag_name != $tag)][0].tag_name // empty')"
|
||||
|
||||
if [ -n "$previous_tag" ]; then
|
||||
commit_messages="$(git log --reverse --format='- %s' "${previous_tag}..${GITEA_SHA}")"
|
||||
full_changelog="${{ gitea.server_url }}/${{ gitea.repository }}/compare/${previous_tag}...${RELEASE_TAG}"
|
||||
else
|
||||
commit_messages="$(git log --reverse --format='- %s' "${GITEA_SHA}")"
|
||||
full_changelog=""
|
||||
fi
|
||||
|
||||
if [ -z "$commit_messages" ]; then
|
||||
commit_messages='- No commits since the previous release'
|
||||
fi
|
||||
|
||||
{
|
||||
echo '## Changes'
|
||||
echo
|
||||
printf '%s\n' "$commit_messages"
|
||||
echo
|
||||
if [ -n "$full_changelog" ]; then
|
||||
echo "**Full Changelog**: ${full_changelog}"
|
||||
fi
|
||||
} > release-notes.md
|
||||
|
||||
jq --null-input \
|
||||
--arg tag "$RELEASE_TAG" \
|
||||
--arg target "$GITEA_SHA" \
|
||||
--rawfile body release-notes.md \
|
||||
'{tag_name: $tag, target_commitish: $target, name: $tag, body: $body}' \
|
||||
> release.json
|
||||
|
||||
release_id="$(printf '%s' "$releases" | jq -r \
|
||||
--arg tag "$RELEASE_TAG" \
|
||||
'.[] | select(.tag_name == $tag) | .id')"
|
||||
if [ -n "$release_id" ]; then
|
||||
method=PATCH
|
||||
release_url="${api_url}/${release_id}"
|
||||
else
|
||||
method=POST
|
||||
release_url="$api_url"
|
||||
fi
|
||||
|
||||
curl --fail-with-body --silent --show-error \
|
||||
--request "$method" \
|
||||
--header "Authorization: token ${GITEA_TOKEN}" \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-binary @release.json \
|
||||
"$release_url"
|
||||
Reference in New Issue
Block a user