use generic composite action
This commit is contained in:
1 parent
24d6c587fa
commit
c6ae6205f0
1 file changed
+7
-65
@@ -1,72 +1,14 @@
|
||||
on:
|
||||
# schedule:
|
||||
# - cron: "* * * * *"
|
||||
schedule:
|
||||
- cron: "@daily"
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
check_releases:
|
||||
runs-on: "ubuntu-latest-intranet"
|
||||
env:
|
||||
TARGET_REPO_OWNER: "prefix-dev"
|
||||
TARGET_REPO_NAME: "pixi"
|
||||
RELEASE_ARTIFACT: "pixi-x86_64-unknown-linux-musl.tar.gz"
|
||||
steps:
|
||||
- name: Check for latest release on GitHub
|
||||
id: check_release
|
||||
run: |
|
||||
echo "::notice::Checking ${TARGET_REPO_OWNER}/${TARGET_REPO_NAME} for new releases"
|
||||
|
||||
# Fetch all releases and sort them by creation date descending, we only need the latest release tag/date info
|
||||
API_OUTPUT=$(curl -s \
|
||||
"https://api.github.com/repos/${{ env.TARGET_REPO_OWNER }}/${{ env.TARGET_REPO_NAME }}/releases?per_page=1")
|
||||
|
||||
# Check if API call failed or returned no data
|
||||
if [ "$API_OUTPUT" == '[]' ]; then
|
||||
echo "::error::No releases found in the target repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "::debug::API output: ${API_OUTPUT}"
|
||||
|
||||
# Extract the tag name and published date of the latest release
|
||||
LATEST_TAG=$(echo "${API_OUTPUT}" | jq -r '.[0].tag_name')
|
||||
PUBLISH_DATE=$(echo "${API_OUTPUT}" | jq -r '.[0].published_at')
|
||||
|
||||
echo "::notice:: Found latest version: ${LATEST_TAG} published on ${PUBLISH_DATE}"
|
||||
|
||||
# Set output variables for subsequent steps
|
||||
echo "latest_tag=${LATEST_TAG}" >> $GITHUB_OUTPUT
|
||||
echo "publish_date=${PUBLISH_DATE}" >> $GITHUB_OUTPUT
|
||||
|
||||
# Check if the release already exists on Gitea
|
||||
- name: Check if release exists on Gitea
|
||||
id: check_release_exists
|
||||
run: |
|
||||
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${{ steps.check_release.outputs.latest_tag }}")
|
||||
|
||||
if [ "$HTTP_STATUS" -eq 200 ]; then
|
||||
echo "::notice::Release already exists. Skipping step."
|
||||
echo "exists=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "::notice::Release does not exist."
|
||||
echo "exists=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Download latest release from GitHub
|
||||
if: steps.check_release_exists.outputs.exists != 'true'
|
||||
run: |
|
||||
DOWNLOAD_URL="https://github.com/${{ env.TARGET_REPO_OWNER }}/${{ env.TARGET_REPO_NAME }}/releases/download/${{ steps.check_release.outputs.latest_tag }}/${{ env.RELEASE_ARTIFACT }}"
|
||||
|
||||
echo "::notice::Downloading release from $DOWNLOAD_URL ..."
|
||||
curl -L -o "${{ env.RELEASE_ARTIFACT }}" "$DOWNLOAD_URL"
|
||||
|
||||
- name: Create and upload release on Gitea
|
||||
if: steps.check_release_exists.outputs.exists != 'true'
|
||||
uses: actions/gitea-release-action@v1
|
||||
- name: Mirror latest release from GitHub
|
||||
uses: actions/mirror-latest-release
|
||||
with:
|
||||
name: ${{ steps.check_release.outputs.latest_tag }}
|
||||
tag_name: ${{ steps.check_release.outputs.latest_tag }}
|
||||
release_name: ${{ steps.check_release.outputs.latest_tag }}
|
||||
body: "Release ${{ steps.check_release.outputs.latest_tag }} published on ${{ steps.check_release.outputs.publish_date }}"
|
||||
files: ./${{ env.RELEASE_ARTIFACT }}
|
||||
owner: "prefix-dev"
|
||||
repo: "pixi"
|
||||
files: "pixi-x86_64-unknown-linux-musl.tar.gz"
|
||||
Reference in new issue
Block a user