Skip to content

Conversation

@thomas-zahner
Copy link
Member

@thomas-zahner thomas-zahner commented Nov 20, 2025

Example run which resulted in this PR. The created PR contained other changes because it was ran from this branch. With the latest commit it should only run on master.

Maybe it would be better to run the workflow in the main repository and create this PR as part of the release workflow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess we could make that a little more robust by checking errors. Bash is notoriously "permissive" on errors. 😅

#! /usr/bin/env bash

set -euo pipefail

POSITION=1 # 0 is nightly, 1 is latest stable release
FILE=src/generate/lychee-version.ts

# Fetch releases with error handling
if ! RELEASES=$(curl --silent --show-error --fail "https://api.github.com/repos/lycheeverse/lychee/releases"); then
    echo "Error: Failed to fetch releases from GitHub API" >&2
    exit 1
fi

# Parse version with error handling
if ! LATEST=$(echo "$RELEASES" | jq -r ".[$POSITION] | .name"); then
    echo "Error: Failed to parse release version" >&2
    exit 1
fi

# Validate we got a non-empty version
if [[ -z "$LATEST" || "$LATEST" == "null" ]]; then
    echo "Error: No valid version found at position $POSITION" >&2
    exit 1
fi

echo "Latest version: $LATEST"

# Check if file exists
if [[ ! -f "$FILE" ]]; then
    echo "Error: File $FILE does not exist" >&2
    exit 1
fi

# Update version file
sed -i -e "s/LYCHEE_VERSION = \"[^\"]*\"/LYCHEE_VERSION = \"$LATEST\"/" "$FILE"

if git status --porcelain | grep -q "$FILE"; then
    echo "New version found: $LATEST"
    
    BRANCH="bump-$LATEST"
    MESSAGE="Bump lychee: $LATEST"
    
    git checkout -b "$BRANCH"
    git add "$FILE"
    git config user.name "lychee bot"
    git config user.email "[email protected]"
    git commit --message "$MESSAGE"
    git push -u origin "$BRANCH"
    gh pr create -B master -H "$BRANCH" --title "$MESSAGE" --body 'Created by Github action'
else
    echo "Version is up to date"
fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree w error checking being good. I think, also, that identifying nightly vs stable should be done more robustly rather than position. Does a stable release always have a digit, or is nightly always called nightly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I agree with both inputs. Although your example @mre seems a bit overly cautious/verbose with all the checks. I even considered to write this in Rust script but it still feels a bit too experimental to me. I'll update the script.

Does a stable release always have a digit, or is nightly always called nightly?

Yes. Running curl "https://api.github.com/repos/lycheeverse/lychee/releases" | jq -r ".[] | .name"

nightly
lychee-v0.21.0
lychee-lib-v0.21.0
lychee-v0.20.1
lychee-lib-v0.20.1
lychee-v0.20.0
lychee-lib-v0.20.0
lychee-v0.19.1
lychee-lib-v0.19.1
lychee-v0.19.0
lychee-lib-v0.19.0
lychee-v0.18.1
lychee-lib-v0.18.1
lychee-v0.18.0
lychee-lib-v0.18.0
lychee-v0.17.0
lychee-lib-v0.17.0
lychee-v0.16.1
lychee-v0.16.0
lychee-lib-v0.16.1
lychee-lib-v0.16.0
Version 0.15.1
Version 0.15.0
Version 0.14.3

So if the order is guaranteed, which I guess it is, we could filter "nightly" and then use the first release. Or we could really parse the version number and use the biggest one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants