Skip to content

Mirror GitLab Release #222

Mirror GitLab Release

Mirror GitLab Release #222

Workflow file for this run

name: Mirror GitLab Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: 'Tag to mirror (e.g. v1.2.3)'
required: true
default: ${GITHUB_REF_NAME}
permissions:
contents: write
jobs:
mirror-release:
runs-on: ubuntu-latest
env:
GITLAB_PROJECT: uniget-org/cli
GITLAB_PROJECT_API: uniget-org%2Fcli
GITLAB_REPO_URL: https://gitlab.com/${GITLAB_PROJECT}
GITLAB_RELEASE_API_URL: https://gitlab.com/${GITLAB_PROJECT}/-/releases/${{ inputs.tag }}
GITLAB_PROJECT_API_URL: "https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_API}/releases/${{ inputs.tag }}"
steps:
- name: Mirror release from GitLab
shell: bash
run: |
set -euo pipefail
echo "Fetching GitLab release for tag: ${{ inputs.tag }}"
if ! curl --silent --show-error --location --fail --output release.json "${GITLAB_PROJECT_API_URL}"; then
echo "ERROR: Failed to fetch GitLab release for tag >${{ inputs.tag }}>."
exit 1
fi
title="$(jq -r '.name // .tag_name' release.json)"
notes_file=release_notes.md
{
echo "Mirrored from GitLab: ${GITLAB_RELEASE_API_URL}"
echo
jq -r '.description // ""' release.json
} >"${notes_file}"
if gh release view "${{ inputs.tag }}" >/dev/null 2>&1; then
echo "Updating existing GitHub release ${{ inputs.tag }}"
gh release edit "${{ inputs.tag }}" --title "${title}" --notes-file "${notes_file}"
else
echo "Creating GitHub release ${{ inputs.tag }}"
gh release create "${{ inputs.tag }}" --title "${title}" --notes-file "${notes_file}"
fi