Check GitHub CLI Version #83
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 GitHub CLI Version | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs daily at midnight UTC | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
check-version: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get latest gh CLI version | |
id: get_version | |
run: | | |
LATEST_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | jq -r .tag_name | sed 's/^v//') | |
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV | |
echo "Latest version: $LATEST_VERSION" | |
- name: Check and update version | |
run: | | |
CURRENT_VERSION=$(cat github-cli-build-version.txt) | |
if [ "$CURRENT_VERSION" != "${{ env.LATEST_VERSION }}" ]; then | |
# Create new branch | |
git checkout -b update-gh-cli-version-${{ env.LATEST_VERSION }} | |
# Update version file | |
echo "${{ env.LATEST_VERSION }}" > github-cli-build-version.txt | |
# Create commit and push | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add github-cli-build-version.txt | |
git commit -m "chore: update GitHub CLI version to ${{ env.LATEST_VERSION }}" | |
git push origin update-gh-cli-version-${{ env.LATEST_VERSION }} | |
# Create PR first | |
PR_URL=$(gh pr create \ | |
--title "chore: update GitHub CLI version to ${{ env.LATEST_VERSION }}" \ | |
--body "Automated PR to update GitHub CLI version from $CURRENT_VERSION to ${{ env.LATEST_VERSION }}" \ | |
--base main \ | |
--head update-gh-cli-version-${{ env.LATEST_VERSION }}) | |
# Enable auto-merge on the created PR | |
gh pr merge --auto --delete-branch --squash "$PR_URL" | |
else | |
echo "Already using the latest version ($CURRENT_VERSION)" | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.WORKFLOW_PAT }} |