Check Dependencies #127
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Dependencies | |
on: | |
schedule: | |
- cron: '0 4 * * *' # Run once a day at 0400 | |
push: | |
paths: | |
- 'code-server/**' | |
- '*.yml' | |
- '.github/workflows/**' | |
jobs: | |
check-dependencies: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Git | |
run: | | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
- name: Run script to check dependencies | |
run: | | |
BALENA_CLI_VERSION=$(grep -oP 'ENV BALENA_CLI_VERSION=\K[^ ]+' ./code-server/Dockerfile) | |
CODE_SERVER_VERSION=$(grep -oP 'FROM lscr.io/linuxserver/code-server:\K[^ ]+' ./code-server/Dockerfile) | |
echo "Checking for updates..." | |
echo "Current Balena CLI version: $BALENA_CLI_VERSION" | |
echo "Current Code Server version: $CODE_SERVER_VERSION" | |
# Use GitHub API to get the latest release versions | |
LATEST_BALENA_CLI_VERSION=$(curl -s https://api.github.com/repos/balena-io/balena-cli/releases/latest | jq -r '.tag_name') | |
LATEST_CODE_SERVER_VERSION=$(curl -s https://api.github.com/repos/linuxserver/docker-code-server/releases/latest | jq -r '.tag_name') | |
echo "Latest Balena CLI version: $LATEST_BALENA_CLI_VERSION" | |
echo "Latest Code Server version: $LATEST_CODE_SERVER_VERSION" | |
# Compare versions and take actions | |
if [ "$BALENA_CLI_VERSION" != "$LATEST_BALENA_CLI_VERSION" ]; then | |
echo "Balena CLI update available!" | |
# Update Balena CLI version in Dockerfile | |
sed -i "s/ENV BALENA_CLI_VERSION=$BALENA_CLI_VERSION/ENV BALENA_CLI_VERSION=$LATEST_BALENA_CLI_VERSION/" ./code-server/Dockerfile | |
fi | |
if [ "$CODE_SERVER_VERSION" != "$LATEST_CODE_SERVER_VERSION" ]; then | |
echo "Code Server update available!" | |
# Update Code Server version in Dockerfile | |
sed -i "s/FROM linuxserver\/code-server:$CODE_SERVER_VERSION/FROM linuxserver\/code-server:$LATEST_CODE_SERVER_VERSION/" ./code-server/Dockerfile | |
fi | |
if [ "$CODE_SERVER_VERSION" != "$LATEST_CODE_SERVER_VERSION" ]; then | |
echo "Balena YAML update available!" | |
# Update version in balena.yml | |
sed -i "s/version: $CODE_SERVER_VERSION/version: $LATEST_CODE_SERVER_VERSION/" balena.yml | |
fi | |
if [ "$CODE_SERVER_VERSION" != "$LATEST_CODE_SERVER_VERSION" ]; then | |
echo "Updating version in README.md" | |
sed -i "s/\(code-server Docker image. (v\)\([^ ]*\)\(.*\))/\1$LATEST_CODE_SERVER_VERSION\3/" README.md | |
fi | |
- name: Create branch, commit, and push changes | |
run: | | |
# Get the current commit hash | |
commit_hash=$(git rev-parse HEAD) | |
# Create a unique branch name | |
branch_name="update-dependencies_$commit_hash" | |
# Create a new branch | |
git checkout -b $branch_name | |
# Check if there are changes to commit | |
if [[ -n $(git status -s) ]]; then | |
# Add and commit changes | |
git add ./code-server/Dockerfile balena.yml | |
git commit -m "Update dependencies, I've got changes for you! :bomb:" | |
# Push the branch to the remote repository | |
git push origin $branch_name | |
# Create a pull request using gh CLI | |
gh pr create --base main --head $branch_name --title "Update dependencies" --body "This pull request updates dependencies. Check for :ant:" | |
else | |
echo "No changes to commit. Exiting without creating a pull request." | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |