Update Dependencies #241
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: Update Dependencies | |
on: | |
schedule: | |
- cron: '0 7 * * *' | |
workflow_dispatch: | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Detect open PR | |
id: detect_open_pr | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
const { data: pullRequests } = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
base: 'main', | |
head: `${context.repo.owner}:updates`, | |
}); | |
// save pr number to github_env | |
if (pullRequests[0]) { | |
require('fs').appendFileSync(process.env.GITHUB_ENV, | |
`PR_NUMBER=${pullRequests[0].number}\n` | |
); | |
} | |
return pullRequests[0]?.head?.ref ?? 'main'; | |
- id: create_token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{ secrets.APP_ID }} | |
private_key: ${{ secrets.APP_PRIVATE_KEY }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.create_token.outputs.token }} | |
ref: ${{ steps.detect_open_pr.outputs.result }} | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
components: rustfmt | |
- name: Do updates | |
run: | | |
{ | |
echo 'PR_BODY<<EOF' | |
node ./.github/workflows/update_deps.mjs ${{ steps.detect_open_pr.outputs.result }} | |
echo EOF | |
} >> $GITHUB_ENV | |
- name: Cargo update | |
run: cargo update | |
- name: Open PR | |
if: steps.detect_open_pr.outputs.result == 'main' | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
token: ${{ steps.create_token.outputs.token }} | |
commit-message: 'ci: Update dependencies' | |
title: Update dependencies | |
body: ${{ env.PR_BODY }} | |
branch: updates | |
- name: Push to existing PR | |
if: steps.detect_open_pr.outputs.result != 'main' | |
run: | | |
if git diff --quiet; then | |
echo "No changes" | |
exit 1 | |
fi | |
git add . | |
git config --local user.email "[email protected]" | |
git config --local user.name "create-o7-app[bot]" | |
git commit -m "ci: Update dependencies" | |
git push origin ${{ steps.detect_open_pr.outputs.result }} | |
- name: Comment on PR | |
if: steps.detect_open_pr.outputs.result != 'main' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ steps.create_token.outputs.token }} | |
script: | | |
await github.rest.issues.createComment({ | |
issue_number: ${{ env.PR_NUMBER }}, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: process.env.PR_BODY, | |
}); |