Skip to content

Commit

Permalink
fix auto release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pitabwire committed Jan 25, 2025
1 parent 9ffeeac commit 143893f
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,31 @@ name: Publish New Release

on:
schedule:
- cron: "0 0 */3 * *" # Runs every 3 days at midnight UTC
- cron: "0 0 */5 * *" # Runs every 3 days at midnight UTC

jobs:
check-draft-exists:
runs-on: ubuntu-latest
outputs:
draft_exists: ${{ steps.check_draft.outputs.draft_exists }}
draft_id: ${{ steps.check_draft.outputs.draft_id }}
draft_tag_name: ${{ steps.check_draft.outputs.draft_tag_name }}
draft_name: ${{ steps.check_draft.outputs.draft_name }}
draft_body: ${{ steps.check_draft.outputs.draft_body }}

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Check if draft release exists
id: check_draft
run: |
DRAFT_RELEASE=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
DRAFT_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/releases)
DRAFT_RELEASE_ID=$(echo $DRAFT_RELEASE | jq '.[] | select(.draft == true) | .id')
DRAFT_RELEASE_TAG_NAME=$(echo $DRAFT_RELEASE | jq '.[] | select(.draft == true) | .tag_name')
DRAFT_RELEASE_NAME=$(echo $DRAFT_RELEASE | jq '.[] | select(.draft == true) | .name')
DRAFT_RELEASE_BODY=$(echo $DRAFT_RELEASE | jq '.[] | select(.draft == true) | .body')
DRAFT_RELEASE_ID=$(echo "$DRAFT_RELEASE" | jq -r '.[] | select(.draft == true) | .id // empty')
echo "draft_id=$DRAFT_RELEASE_ID" >> $GITHUB_OUTPUT
echo "draft_tag_name=$DRAFT_RELEASE_TAG_NAME" >> $GITHUB_OUTPUT
echo "draft_name=$DRAFT_RELEASE_NAME" >> $GITHUB_OUTPUT
echo "draft_body=$DRAFT_RELEASE_BODY" >> $GITHUB_OUTPUT
if [ -z "$DRAFT_RELEASE_ID" ]; then
echo "No draft exists for automatic publishing"
exit 0
else
echo "draft_exists=true" >> $GITHUB_OUTPUT
fi
publish-release:
needs: check-draft-exists
runs-on: ubuntu-latest
if: needs.check-draft-exists.outputs.draft_id != ''
steps:

- name: Check out the repository
uses: actions/checkout@v4

- name: Publish the release
uses: eregon/publish-release@v1
with:
release_id: ${{ needs.check-draft-exists.outputs.draft_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 143893f

Please sign in to comment.