From 5ae6214726e558038ecaf87eab91fe554ab0461d Mon Sep 17 00:00:00 2001 From: xgreenx Date: Thu, 12 Oct 2023 12:34:42 +0200 Subject: [PATCH 1/2] Updated CI to run `cargo update` weekly --- .github/workflows/dependencies.yml | 117 +++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .github/workflows/dependencies.yml diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml new file mode 100644 index 00000000000..dd7b6c338ef --- /dev/null +++ b/.github/workflows/dependencies.yml @@ -0,0 +1,117 @@ +# Automatically run `cargo update` periodically + +--- +name: Bump dependencies in Cargo.lock +on: + schedule: + # Run weekly + - cron: '0 0 * * Sun' + workflow_dispatch: + # Needed so we can run it manually +permissions: + contents: read +defaults: + run: + shell: bash +env: + # So cargo doesn't complain about unstable features + RUSTC_BOOTSTRAP: 1 + RUST_VERSION: 1.72.0 + PR_TITLE: Weekly `cargo update` + PR_MESSAGE: | + Automation to keep dependencies in `Cargo.lock` current. + + The following is the output from `cargo update`: + COMMIT_MESSAGE: "cargo update \n\n" + +jobs: + update: + if: github.repository_owner == 'fuel-core' + name: update dependencies + runs-on: buildjet-4vcpu-ubuntu-2204 + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + + - name: cargo update + # Remove first line that always just says "Updating crates.io index" + run: cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log + - name: upload Cargo.lock artifact for use in PR + uses: actions/upload-artifact@v3 + with: + name: Cargo-lock + path: Cargo.lock + retention-days: 1 + - name: upload cargo-update log artifact for use in PR + uses: actions/upload-artifact@v3 + with: + name: cargo-updates + path: cargo_update.log + retention-days: 1 + + pr: + if: github.repository_owner == 'fuel-core' + name: amend PR + needs: update + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: checkout the source code + uses: actions/checkout@v4 + + - name: download Cargo.lock from update job + uses: actions/download-artifact@v3 + with: + name: Cargo-lock + - name: download cargo-update log from update job + uses: actions/download-artifact@v3 + with: + name: cargo-updates + + - name: craft PR body and commit message + run: | + echo "${COMMIT_MESSAGE}" > commit.txt + cat cargo_update.log >> commit.txt + + echo "${PR_MESSAGE}" > body.md + echo '```txt' >> body.md + cat cargo_update.log >> body.md + echo '```' >> body.md + + - name: commit + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git switch --force-create cargo_update + git add ./Cargo.lock + git commit --no-verify --file=commit.txt + + - name: push + run: git push --no-verify --force --set-upstream origin cargo_update + + - name: edit existing open pull request + id: edit + # Don't fail job if we need to open new PR + continue-on-error: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Exit with error if PR is closed + STATE=$(gh pr view cargo_update --repo $GITHUB_REPOSITORY --json state --jq '.state') + if [[ "$STATE" != "OPEN" ]]; then + exit 1 + fi + + gh pr edit cargo_update --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY + + - name: open new pull request + # Only run if there wasn't an existing PR + if: steps.edit.outcome != 'success' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh pr create --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY From 37a3826af90daf3e601610a6c298869c4d237dc8 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Thu, 12 Oct 2023 14:31:51 +0200 Subject: [PATCH 2/2] Updated CI to run `cargo update` weekly --- .github/workflows/dependencies.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index dd7b6c338ef..513818ff53e 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -26,7 +26,6 @@ env: jobs: update: - if: github.repository_owner == 'fuel-core' name: update dependencies runs-on: buildjet-4vcpu-ubuntu-2204 steps: @@ -53,10 +52,9 @@ jobs: retention-days: 1 pr: - if: github.repository_owner == 'fuel-core' name: amend PR needs: update - runs-on: ubuntu-latest + runs-on: buildjet-4vcpu-ubuntu-2204 permissions: contents: write pull-requests: write