From fde587cc473a4a0aa867f9669d5ae257e1718dc7 Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Thu, 26 Sep 2024 19:00:32 -0400 Subject: [PATCH] chore(ci): Move to release-plz Remove home-rolled automated release scripts in favor of release-plz --- .github/actions/sync-bsp-versions/action.yml | 9 - .../sync-bsp-versions/update-from-hal.py | 24 --- .github/actions/sync-pac-versions/action.yml | 9 - .../sync-pac-versions/update-from-pac.py | 25 --- .github/dependabot.yml | 7 + .github/workflows/bump-crates.yml | 135 -------------- .github/workflows/bump-t2-bsp.yml | 96 ---------- .github/workflows/release-crates.yml | 176 ------------------ .github/workflows/release.yml | 34 ++++ .github/workflows/update_changelog.py | 38 ---- .release-plz.toml | 13 ++ Cargo.toml | 19 +- 12 files changed, 71 insertions(+), 514 deletions(-) delete mode 100644 .github/actions/sync-bsp-versions/action.yml delete mode 100755 .github/actions/sync-bsp-versions/update-from-hal.py delete mode 100644 .github/actions/sync-pac-versions/action.yml delete mode 100755 .github/actions/sync-pac-versions/update-from-pac.py create mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/bump-crates.yml delete mode 100644 .github/workflows/bump-t2-bsp.yml delete mode 100644 .github/workflows/release-crates.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/update_changelog.py create mode 100644 .release-plz.toml diff --git a/.github/actions/sync-bsp-versions/action.yml b/.github/actions/sync-bsp-versions/action.yml deleted file mode 100644 index f19093da27de..000000000000 --- a/.github/actions/sync-bsp-versions/action.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: 'Sync BSPs to HAL version' -description: 'Updates BSP files to point to latest HAL' -runs: - using: "composite" - steps: - - run: sudo apt-get install python3-pip && pip install tomlkit - shell: bash - - run: python3 ${{ github.action_path }}/update-from-hal.py - shell: bash diff --git a/.github/actions/sync-bsp-versions/update-from-hal.py b/.github/actions/sync-bsp-versions/update-from-hal.py deleted file mode 100755 index cc31b2a4000d..000000000000 --- a/.github/actions/sync-bsp-versions/update-from-hal.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 - -from tomlkit import parse, dumps -from pathlib import Path -import json -import sys - -hal_path = Path("hal") / "Cargo.toml" -hal = parse(hal_path.read_text()) -hal_version = hal["package"]["version"] - -crates = Path("crates.json") -boards = json.loads(crates.read_text())["boards"] -board_names = [name for name, info in boards.items() if info["tier"] == 1] - -for name in board_names: - bsp_path = Path("boards") / name / "Cargo.toml" - bsp = parse(bsp_path.read_text()) - bsp_version = bsp["dependencies"]["atsamd-hal"]["version"] - if bsp_version != hal_version: - print(f"Upgrading {name} from {bsp_version} to {hal_version}.", file=sys.stderr) - bsp["dependencies"]["atsamd-hal"]["version"] = hal_version - bsp_path.write_text(dumps(bsp)) - diff --git a/.github/actions/sync-pac-versions/action.yml b/.github/actions/sync-pac-versions/action.yml deleted file mode 100644 index 1a32321d55c6..000000000000 --- a/.github/actions/sync-pac-versions/action.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: 'Sync HAL to PAC versions' -description: 'Updates HAL file with latest PAC versions' -runs: - using: "composite" - steps: - - run: sudo apt-get install python3-pip && pip install --user tomlkit - shell: bash - - run: python3 ${{ github.action_path }}/update-from-pac.py - shell: bash diff --git a/.github/actions/sync-pac-versions/update-from-pac.py b/.github/actions/sync-pac-versions/update-from-pac.py deleted file mode 100755 index 0a144df0a7ef..000000000000 --- a/.github/actions/sync-pac-versions/update-from-pac.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 - -from tomlkit import parse, dumps -from pathlib import Path -import sys - -hal_path = Path("hal") / "Cargo.toml" -hal = parse(hal_path.read_text()) - -pacs = {} -for path in Path("pac").glob("atsam*/Cargo.toml"): - name = path.parent.name - pacs[name] = parse(path.read_text()) - -for name, pac in pacs.items(): - hal_version = hal["dependencies"][name]["version"] - pac_version = pac["package"]["version"] - if hal_version == pac_version: - print(f"HAL dependency on {name} is up-to-date.", file=sys.stderr) - else: - hal["dependencies"][name]["version"] = pac_version - msg = f"HAL dependency on {name} upgraded from {hal_version} to {pac_version}." - print(msg, file=sys.stderr) - -hal_path.write_text(dumps(hal)) diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000000..7ee8cf824921 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + # Check for updates every Monday + schedule: + interval: "weekly" diff --git a/.github/workflows/bump-crates.yml b/.github/workflows/bump-crates.yml deleted file mode 100644 index 44d183af37bd..000000000000 --- a/.github/workflows/bump-crates.yml +++ /dev/null @@ -1,135 +0,0 @@ -name: Bump crate versions -on: - workflow_dispatch: - inputs: - pac_bump: - description: 'PAC version bump (none/patch/minor/major)' - required: true - default: 'none' - hal_bump: - description: 'HAL version bump (none/patch/minor/major)' - required: true - default: 'none' - bsp_bump: - description: 'T1 BSP version bump (none/patch/minor/major)' - required: true - default: 'none' - -jobs: - bump-versions: - runs-on: ubuntu-latest - steps: - - name: Set up Rust - run: | - rustup set profile minimal - rustup override set stable - - uses: actions/checkout@v4 - with: - ssh-key: ${{ secrets.ATSAMD_BOT_SSH_PRIVKEY }} - - name: Setup - shell: bash - run: | - set -ex - cargo install cargo-edit - - - name: Bump PAC versions - if: github.event.inputs.pac_bump != 'none' - shell: bash - run: | - set -ex - - for dir in pac/*/ ; do - # Remove the trailing slash - dir=${dir%/} - manifest="$dir/Cargo.toml" - - # Bump the PAC version - cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.pac_bump }} - - # Update the changelog - version=$(cargo metadata --manifest-path $manifest --no-deps --format-version 1 | jq -r '.packages[0].version') - python3 .github/workflows/update_changelog.py $dir $version - done - - - name: Update HAL deps - uses: ./.github/actions/sync-pac-versions - - - name: Bump HAL version - if: github.event.inputs.hal_bump != 'none' - shell: bash - run: | - set -ex - - # Bump the HAL version - cargo set-version --manifest-path "hal/Cargo.toml" --exclude atsamd-hal-macros --bump ${{ github.event.inputs.hal_bump }} - - # Update the changelog - version=$(cargo metadata --manifest-path "hal/Cargo.toml" --no-deps --format-version 1 | jq -r '.packages[0].version') - python3 .github/workflows/update_changelog.py hal/ $version - - - name: Update BSP deps - uses: ./.github/actions/sync-bsp-versions - - - name: Bump BSP versions - if: github.event.inputs.bsp_bump != 'none' - shell: bash - run: | - set -ex - - jq -r '.boards | to_entries | map(select(.value.tier == 1) | .key) | .[]' crates.json | while read dir; do - manifest="boards/$dir/Cargo.toml" - - # Bump the BSP version - cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.bsp_bump }} - - # Update the changelog - version=$(cargo metadata --manifest-path $manifest --no-deps --format-version 1 | jq -r '.packages[0].version') - python3 .github/workflows/update_changelog.py "boards/$dir/" $version - done - - - name: Generate patch - shell: bash - run: | - git diff > bump.patch - - - name: Upload diff - uses: actions/upload-artifact@v4 - with: - name: bump.patch - path: bump.patch - - - name: Cleanup - shell: bash - run: | - set -ex - rm bump.patch - - - name: Create Pull Request - id: cpr - uses: peter-evans/create-pull-request@v6 - with: - commit-message: | - Bump crate versions - - HAL: ${{ github.event.inputs.hal_bump }} - Tier 1 BSPs: ${{ github.event.inputs.bsp_bump }} - PACs: ${{ github.event.inputs.pac_bump }} - committer: GitHub - author: atsamd-bot - signoff: false - branch: bump-versions - delete-branch: true - title: '[atsamd-bot] Bump crate versions' - body: | - Automated bump of crate versions. - - Workflow launched by `${{ github.actor }}` - - Workflow: [bump-crates.yml][1] - - PAC bump = `${{ github.event.inputs.pac_bump }}` - - HAL bump = `${{ github.event.inputs.hal_bump }}` - - BSP bump = `${{ github.event.inputs.bsp_bump }}` - - [1]: https://github.com/atsamd-rs/atsamd/tree/master/.github/workflows - labels: | - automated pr - version-bump - draft: false diff --git a/.github/workflows/bump-t2-bsp.yml b/.github/workflows/bump-t2-bsp.yml deleted file mode 100644 index 91150556de40..000000000000 --- a/.github/workflows/bump-t2-bsp.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: Bump version of a single Tier 2 crate -on: - workflow_dispatch: - inputs: - bsp_name: - description: 'Name of Tier 2 BSP to bump' - required: true - bsp_bump: - description: 'Tier 2 BSP version bump (none/patch/minor/major)' - required: true - default: 'none' - -jobs: - bump-versions: - runs-on: ubuntu-latest - steps: - - name: Set up Rust - run: | - rustup set profile minimal - rustup override set stable - - uses: actions/checkout@v4 - with: - ssh-key: ${{ secrets.ATSAMD_BOT_SSH_PRIVKEY }} - - name: Setup - shell: bash - run: | - set -ex - cargo install cargo-edit - - - name: Bump BSP version - if: github.event.inputs.bsp_bump != 'none' - shell: bash - run: | - set -ex - bsp=${{github.event.inputs.bsp_name }} - - if [ ! -d "boards/$bsp" ]; then - echo "BSP $bsp does not exist" - exit 1 - fi - - if jq -r '.boards | to_entries | map(select(.value.tier == 2) | .key) | .[]' crates.json | grep -q $bsp; then - manifest="boards/$bsp/Cargo.toml" - - # Bump the BSP version - cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.bsp_bump }} - - # Update the changelog - version=$(cargo metadata --manifest-path $manifest --no-deps --format-version 1 | jq -r '.packages[0].version') - python3 .github/workflows/update_changelog.py "boards/$bsp/" $version - else - echo "BSP $bsp is not Tier 2." - exit 2 - fi - - - name: Generate patch - shell: bash - run: | - git diff > bump.patch - - - name: Upload diff - uses: actions/upload-artifact@v4 - with: - name: bump.patch - path: bump.patch - - - name: Cleanup - shell: bash - run: | - set -ex - rm bump.patch - - - name: Create Pull Request - id: cpr - uses: peter-evans/create-pull-request@v6 - with: - commit-message: | - Bump ${{ github.event.inputs.bsp_name }} (${{ github.event.inputs.bsp_bump }}) - committer: GitHub - author: atsamd-bot - signoff: false - branch: bump-${{ github.event.inputs.bsp_name }} - delete-branch: true - title: '[atsamd-bot] Bump crate versions' - body: | - Automated bump of Tier 2 BSP. - - Workflow launched by `${{ github.actor }}` - - Workflow: [bump-t2-bsp.yml][1] - - BSP name = `${{ github.event.inputs.bsp_name}}` - - Bump = `${{ github.event.inputs.bsp_bump }}` - - [1]: https://github.com/atsamd-rs/atsamd/tree/master/.github/workflows - labels: | - automated pr - version-bump - draft: false diff --git a/.github/workflows/release-crates.yml b/.github/workflows/release-crates.yml deleted file mode 100644 index 285a20cb5767..000000000000 --- a/.github/workflows/release-crates.yml +++ /dev/null @@ -1,176 +0,0 @@ -name: Release crates -on: - workflow_dispatch: - inputs: - release_pac: - description: 'Release PAC (yes/no)' - required: true - default: 'yes' - release_hal: - description: 'Release HAL (yes/no)' - required: true - default: 'yes' - release_bsp: - description: 'Release BSPs (yes/no)' - required: true - default: 'yes' -jobs: - release-crates: - runs-on: ubuntu-latest - steps: - - name: Install Rust - run: | - rustup set profile minimal - rustup override set stable - rustup target add thumbv6m-none-eabi - rustup target add thumbv7em-none-eabihf - - - name: Login - run: cargo login ${CRATES_IO_TOKEN} - env: - CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} - - - name: Release PAC crates - if: github.event.inputs.release_pac == 'yes' - shell: bash - run: | - set -ex - - # Run `cargo publish` on each PAC. - # Unfortunately, cargo publish errors if the crate is already uploaded, - # and there is no way to turn that off. As a result, we need to do some - # janky hacks to detect that condition and ignore it. - # - # Specifically, we ignore the exit code but capture the stderr. If - # the standard error contains ' is already uploaded', then it must - # be the error we dont care about, so we exit the subshell with a - # success status. - # - # All errors start with the form 'error: ', so we detect that and - # bail the subshell to crash out on other publish errors. - # - # Before publishing, we also tag each PAC with its current version. - # If creating+pushing the tag fails, we check if there already is an - # identical tag at the same commit, and continue processing if that's - # the case. If tagging fails for any other reason, bail the subshell. - - for d in pac/*/ - do - ( - cd "${d}" - - PAC_NAME="${d#pac/}" - PAC_NAME="${PAC_NAME%/}" - - VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') - TAG_NAME="${PAC_NAME}-${VERSION}" - - if ! git tag -a $TAG_NAME -m "${PAC_NAME} release ${VERSION}" && git push origin tag "$TAG_NAME"; then - if git tag --points-at "$(git rev-parse HEAD)" | grep "$TAG_NAME" > /dev/null; then - echo '(and points at this commit). Continuing.' - else - false - fi - fi - - set +e - PUBLISH_ERR=$(cargo publish 2>&1 >/dev/null) - set -e - if [[ "$PUBLISH_ERR" == *" is already uploaded"* ]]; then - exit 0 - fi - if [[ "$PUBLISH_ERR" == *"error: "* ]]; then - echo "$PUBLISH_ERR" - exit 1 - fi - ) - done - - - uses: actions/checkout@v4 - with: - ssh-key: ${{ secrets.ATSAMD_BOT_SSH_PRIVKEY }} - - - name: Release HAL crate - if: github.event.inputs.release_hal == 'yes' - shell: bash - run: | - set -ex - - # Force update of the registry - cargo update || true - - cd hal - - VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') - TAG_NAME="atsamd-hal-${VERSION}" - - # Create+push a git tag. If that fails, check if an identical tag already exists at the - # same commit. Bail otherwise. - if ! git tag -a $TAG_NAME -m "atsamd-hal release ${VERSION}" && git push origin tag "$TAG_NAME"; then - if git tag --points-at "$(git rev-parse HEAD)" | grep "$TAG_NAME" > /dev/null; then - echo '(and points at this commit). Continuing.' - else - false - fi - fi - - - cargo publish - - - - name: Release BSP crates - if: github.event.inputs.release_bsp == 'yes' - shell: bash - run: | - set -ex - - # Force update of the registry - cargo update || true - - sudo apt-get install -y jq - - # Unfortunately, cargo publish errors if the crate is already uploaded, - # and there is no way to turn that off. As a result, we need to do some - # janky hacks to detect that condition and ignore it. - # - # Specifically, we ignore the exit code but capture the stderr. If - # the standard error contains ' is already uploaded', then it must - # be the error we dont care about, so we exit the subshell with a - # success status. - # - # All errors start with the form 'error: ', so we detect that and - # bail the subshell to crash out on other publish errors. - # - # Before publishing, we also tag each BSP with its current version. - # If creating+pushing the tag fails, we check if there already is an - # identical tag at the same commit, and continue processing if that's - # the case. If tagging fails for any other reason, bail the subshell. - - for bsp in $(cat crates.json | jq -Mr -c '.boards | keys[]'); - do - ( - cd "boards/${bsp}" - - VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') - TAG_NAME="${bsp}-${VERSION}" - - if ! git tag -a $TAG_NAME -m "${bsp} release ${VERSION}" && git push origin tag "$TAG_NAME"; then - if git tag --points-at "$(git rev-parse HEAD)" | grep "$TAG_NAME" > /dev/null; then - echo '(and points at this commit). Continuing.' - else - false - fi - fi - - set +e - PUBLISH_ERR=$(cargo publish 2>&1 >/dev/null) - set -e - if [[ "$PUBLISH_ERR" == *" is already uploaded"* ]]; then - exit 0 - fi - if [[ "$PUBLISH_ERR" == *"error: "* ]]; then - echo "$PUBLISH_ERR" - exit 1 - fi - ) - done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000000..d60433563d8f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release-plz + +permissions: + pull-requests: write + contents: write + +on: + push: + branches: + - master + +jobs: + release-plz: + name: Release-plz + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: thumbv6m-none-eabi, thumbv7em-none-eabihf + + - name: Run release-plz + uses: MarcoIeni/release-plz-action@v0.5 + # Remove the next two lines when ready to go live with release-plz + with: + command: release-pr + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} diff --git a/.github/workflows/update_changelog.py b/.github/workflows/update_changelog.py deleted file mode 100644 index d9cf7b20c624..000000000000 --- a/.github/workflows/update_changelog.py +++ /dev/null @@ -1,38 +0,0 @@ -import argparse -import re -import sys - -def update_changelog(changelog_path, version): - try: - with open(changelog_path, 'r', encoding='utf-8') as f: - changelog = f.read() - except FileNotFoundError: - sys.stderr.write(f"Error: Changelog file not found at {changelog_path}.") - sys.exit(1) - - unreleased_pattern = re.compile(r'^# unreleased.*$', re.IGNORECASE | re.MULTILINE) - - if not unreleased_pattern.search(changelog): - sys.stderr.write(f"Error: No 'Unreleased' section found in {changelog_path}.") - sys.exit(2) - - replacement_text = f"# Unreleased Changes\n\n# v{version}" - updated_changelog = re.sub(unreleased_pattern, replacement_text, changelog) - with open(changelog_path, 'w', encoding='utf-8') as f: - f.write(updated_changelog) - - print(f"Changelog updated successfully with version {version}.") - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Update crate changelog by parsing version from Cargo manifest") - parser.add_argument('crate_path', help="Path to the crate") - parser.add_argument('crate_version', help="Version of the crate") - - args = parser.parse_args() - - # Get the crate version from Cargo.toml - manifest_path = f'{args.crate_path}/Cargo.toml' - - # Update the changelog - crate_changelog_path = f'{args.crate_path}/CHANGELOG.md' - update_changelog(crate_changelog_path, args.crate_version) diff --git a/.release-plz.toml b/.release-plz.toml new file mode 100644 index 000000000000..1ec509937def --- /dev/null +++ b/.release-plz.toml @@ -0,0 +1,13 @@ +[workspace] +git_release_name = "{{ package }}-{{ version }}" +git_tag_name = "{{ package }}-{{ version }}" +pr_labels = ["release", "automated pr"] +git_tag_enable = false # # Remove this line when ready to go live with release-plz +publish = false # Remove this line when ready to go live with release-plz +publish_timeout = "10m" + +# Only try to publish releases when a release PR is merged +release_always = false + +[changelog] +protect_breaking_commits = true \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 54874e2ffc42..6dbce0c83c08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,19 @@ [workspace] resolver = "2" -members = ["hal", "atsamd-hal-macros"] -exclude = ["pac", "boards"] \ No newline at end of file +members = [ + "hal", + "atsamd-hal-macros", + "pac/*", + "boards/*", +] + +[profile.dev] +incremental = false +codegen-units = 1 +debug = true +lto = false + +[profile.release] +debug = true +lto = true +opt-level = "s"