Skip to content

Update tools

Update tools #185

Workflow file for this run

name: Update tools
permissions:
pull-requests: write
contents: write
on:
workflow_dispatch:
schedule:
# Run every day at 18:30 UTC
- cron: '30 18 * * *'
concurrency:
# Ensure this workflow does not run twice at the same time
group: ${{ github.workflow }}
jobs:
fetch-new-versions:
name: Fetch new versions
runs-on: ubuntu-latest
outputs:
new_versions: ${{ steps.new_versions.outputs.new_versions }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pesde
uses: axiom-co/setup-pesde@b690699ace34169731b6b2a1c93b2008472038a7
with:
cache: true
token: ${{ secrets.PESDE_TOKEN }}
- name: Install dependencies
run: pesde install --locked
- name: Fetch new versions
id: new_versions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
lune -V
new_versions="$(lune run update_tools --json | jq -c 'to_entries | map({ package: .key, versions: .value })')"
echo "new_versions=$new_versions" >> "$GITHUB_OUTPUT"
update-package:
name: Update ${{ matrix.package }}
runs-on: ubuntu-latest
needs: fetch-new-versions
if: needs.fetch-new-versions.outputs.new_versions != '[]'
strategy:
matrix:
include: ${{ fromJSON(needs.fetch-new-versions.outputs.new_versions) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pesde
uses: axiom-co/setup-pesde@b690699ace34169731b6b2a1c93b2008472038a7
with:
cache: true
- name: Install dependencies
run: pesde install --locked
- name: Update package
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Switch to branch
branch="update/${{ matrix.package }}"
git branch -f "$branch"
git switch "$branch"
# Build PR body
pr_body=""
pr_body+=$'**🤖 This PR is automatically generated.**\n\n'
pr_body+=$'It contains the following new versions for `${{ matrix.package }}` as separate commits.\n\n'
versions="$(echo '${{ toJson(matrix.versions) }}' | jq -r '.[]')"
while read -r version; do
# Perform the update
lune run update_tools "${{ matrix.package }}" "$version"
pesde install
# Stage & commit changes
git add .
git commit -m "${{ matrix.package }}: $version"
commit_hash=$(git rev-parse HEAD)
pr_body+="- $commit_hash - $version"$'\n'
done <<< "$versions"
pr_body+=$'\n'
pr_body+="Merging this PR will automatically publish the new package versions."
# Push changes
git push --force origin "$branch"
# Create/Edit PR
if gh pr view --json state --jq '.state' 2>/dev/null | grep -q "OPEN"; then
pr_command="edit"
echo "Editing PR..."
else
pr_command="create"
echo "Creating PR..."
fi
latest_version="$(echo '${{ toJson(matrix.versions) }}' | jq -r '.[-1]')"
gh pr "$pr_command" \
--title "${{ matrix.package }}: $latest_version" \
--body "$pr_body" \
>> $GITHUB_STEP_SUMMARY