name: Create Gitea Release description: Create git tag, create Gitea release and upload zip assets from dist inputs: gitea_url: description: Gitea instance URL required: false default: https://git.scuroneko.dev repo_owner: description: Repository owner or organization required: true repo_name: description: Repository name required: true token: description: Gitea API token required: true tag_name: description: Git tag name required: true release_name: description: Release display name required: true target_commitish: description: Target branch or commit required: false default: main assets_glob: description: Release assets glob required: false default: dist/*.zip runs: using: composite steps: - name: Create git tag shell: bash env: GITEA_TOKEN: ${{ inputs.token }} GITEA_URL: ${{ inputs.gitea_url }} REPO_OWNER: ${{ inputs.repo_owner }} REPO_NAME: ${{ inputs.repo_name }} TAG_NAME: ${{ inputs.tag_name }} run: | set -euo pipefail [ -n "$TAG_NAME" ] || { echo "TAG_NAME is empty"; exit 1; } git config user.name "Gitea Actions" git config user.email "actions@gitea.local" git remote set-url origin \ "https://x-access-token:${GITEA_TOKEN}@${GITEA_URL#https://}/${REPO_OWNER}/${REPO_NAME}.git" if git ls-remote --tags origin "refs/tags/$TAG_NAME" | grep -q "$TAG_NAME"; then echo "Remote tag $TAG_NAME already exists" exit 0 fi if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then echo "Local tag $TAG_NAME already exists" else git tag "$TAG_NAME" fi git push origin "$TAG_NAME" for _ in 1 2 3 4 5; do if git ls-remote --tags origin "refs/tags/$TAG_NAME" | grep -q "$TAG_NAME"; then echo "Remote tag $TAG_NAME is visible" exit 0 fi echo "Waiting for remote tag $TAG_NAME to become visible..." sleep 2 done echo "Remote tag $TAG_NAME is still not visible after push" exit 1 - name: Create Gitea release id: create_release shell: bash env: GITEA_TOKEN: ${{ inputs.token }} GITEA_URL: ${{ inputs.gitea_url }} REPO_OWNER: ${{ inputs.repo_owner }} REPO_NAME: ${{ inputs.repo_name }} TAG_NAME: ${{ inputs.tag_name }} RELEASE_NAME: ${{ inputs.release_name }} TARGET_COMMITISH: ${{ inputs.target_commitish }} run: | set -euo pipefail body=$(jq -n \ --arg tag "$TAG_NAME" \ --arg target "$TARGET_COMMITISH" \ --arg name "$RELEASE_NAME" \ --arg body "Release $RELEASE_NAME" \ '{ tag_name: $tag, target_commitish: $target, name: $name, body: $body, draft: false, prerelease: false }') http_code=$(curl -sS -o response.json -w "%{http_code}" \ -X POST "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d "$body") echo "HTTP code: $http_code" cat response.json echo if [ "$http_code" = "409" ]; then echo "Release already exists, trying to find it..." http_code=$(curl -sS -o response.json -w "%{http_code}" \ "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$TAG_NAME" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Accept: application/json") echo "HTTP code: $http_code" cat response.json echo fi if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then echo "Failed to create or read release" exit 1 fi release_id=$(jq -r '.id' response.json) if [ "$release_id" = "null" ] || [ -z "$release_id" ]; then echo "Failed to get release id" exit 1 fi echo "release_id=$release_id" >> "$GITHUB_OUTPUT" - name: Upload release assets shell: bash env: GITEA_TOKEN: ${{ inputs.token }} GITEA_URL: ${{ inputs.gitea_url }} REPO_OWNER: ${{ inputs.repo_owner }} REPO_NAME: ${{ inputs.repo_name }} RELEASE_ID: ${{ steps.create_release.outputs.release_id }} ASSETS_GLOB: ${{ inputs.assets_glob }} run: | set -euo pipefail found=0 for file in $ASSETS_GLOB; do [ -f "$file" ] || continue found=1 filename="$(basename "$file")" encoded_name="$(jq -rn --arg v "$filename" '$v|@uri')" echo "Uploading $filename" http_code=$(curl -sS -o upload-response.json -w "%{http_code}" \ -X POST \ "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases/$RELEASE_ID/assets?name=$encoded_name" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Accept: application/json" \ -H "Content-Type: multipart/form-data" \ -F "attachment=@$file") echo "HTTP code: $http_code" cat upload-response.json echo if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then echo "Failed to upload $filename" exit 1 fi done if [ "$found" = "0" ]; then echo "No assets found by glob: $ASSETS_GLOB" exit 1 fi