Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/bump-lychee-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Bump lychee version

on:
repository_dispatch:
workflow_dispatch:
schedule:
- cron: "00 18 * * *"

jobs:
bumpLycheeVersion:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Bump lychee version
run: ./bump-lychee.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions bump-lychee.sh
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/env bash

POSITION=1 # 0 is nightly, 1 is latest stable release
LATEST=$(curl "https://api.github.com/repos/lycheeverse/lychee/releases" | jq -r ".[$POSITION] | .name")
FILE=src/generate/lychee-version.ts

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

if git status --porcelain | grep $FILE; then
echo New version found: $LATEST
git add $FILE
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