From 0acfac55ccf6cf46b29431989565d56f12b6ba2c Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Wed, 4 Sep 2024 17:07:04 -0400 Subject: [PATCH 1/7] Don't release crates when bumping versions --- .github/actions/sync-bsp-versions/action.yml | 2 +- .github/actions/sync-pac-versions/action.yml | 2 +- .github/workflows/bump-crates.yml | 57 +++++++------------- 3 files changed, 21 insertions(+), 40 deletions(-) diff --git a/.github/actions/sync-bsp-versions/action.yml b/.github/actions/sync-bsp-versions/action.yml index 97f510a01e65..f19093da27de 100644 --- a/.github/actions/sync-bsp-versions/action.yml +++ b/.github/actions/sync-bsp-versions/action.yml @@ -3,7 +3,7 @@ description: 'Updates BSP files to point to latest HAL' runs: using: "composite" steps: - - run: sudo apt install python3-pip && pip install tomlkit + - 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-pac-versions/action.yml b/.github/actions/sync-pac-versions/action.yml index 43d9bcc47fe4..1a32321d55c6 100644 --- a/.github/actions/sync-pac-versions/action.yml +++ b/.github/actions/sync-pac-versions/action.yml @@ -3,7 +3,7 @@ description: 'Updates HAL file with latest PAC versions' runs: using: "composite" steps: - - run: sudo apt install python3-pip && pip install --user tomlkit + - 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/workflows/bump-crates.yml b/.github/workflows/bump-crates.yml index 6f95f9b2e3c6..6bbbba99ee46 100644 --- a/.github/workflows/bump-crates.yml +++ b/.github/workflows/bump-crates.yml @@ -38,7 +38,7 @@ jobs: shell: bash run: | set -ex - cargo install cargo-workspace2 + cargo install cargo-edit - name: Bump PAC versions if: github.event.inputs.pac_bump != 'none' @@ -46,20 +46,13 @@ jobs: run: | set -ex - # Create a fake workspace file for all PACs. - echo "[workspace]" > Cargo.toml - echo "members = [" >> Cargo.toml - for d in pac/*/ ; do echo " \"${d::-1}\"," >> Cargo.toml; done - echo "]" >> Cargo.toml - echo "" >> Cargo.toml + for dir in pac/*/ ; do + # Remove the trailing slash + dir=${dir%/} - # Create a ws2 query string for all PACs. - pacs=$(for d in pac/*/ ; do echo -n "${d:4:${#d}-5} "; done ) - pacs=${pacs::-1} # Trim trailing space - - echo "y" | cargo ws2 [ "${pacs}" ] publish ${{ github.event.inputs.pac_bump }} - - git checkout Cargo.toml + # Bump the PAC version + cargo set-version --manifest-path "$dir/Cargo.toml" --bump ${{ github.event.inputs.pac_bump }} + done - name: Update HAL deps if: github.event.inputs.sync_hal == 'yes' @@ -71,16 +64,8 @@ jobs: run: | set -ex - # Create a fake workspace file for the HAL. - echo "[workspace]" > Cargo.toml - echo "members = [" >> Cargo.toml - echo ' "hal",' >> Cargo.toml - echo "]" >> Cargo.toml - echo "" >> Cargo.toml - - echo "y" | cargo ws2 [ "atsamd-hal" ] publish ${{ github.event.inputs.hal_bump }} - - git checkout Cargo.toml + # Bump the HAL version + cargo set-version --manifest-path "hal/Cargo.toml" --exclude atsamd-hal-macros --bump ${{ github.event.inputs.hal_bump }} - name: Update BSP deps if: github.event.inputs.sync_bsp == 'yes' @@ -92,19 +77,10 @@ jobs: run: | set -ex - T1_BOARDS=$(cat crates.json | jq -Mr -c '[.boards | to_entries | map([.key, .value.tier]) | .[] | select(.[1] == 1) | .[0]] | join(" ")') - - # Create a fake workspace file for all BSPs. - echo "[workspace]" > Cargo.toml - echo "members = [" >> Cargo.toml - for d in $T1_BOARDS; do echo " \"boards/${d}\"," >> Cargo.toml; done - echo "]" >> Cargo.toml - echo "" >> Cargo.toml - - echo "y" | cargo ws2 [ "${T1_BOARDS}" ] publish ${{ github.event.inputs.bsp_bump }} - - git checkout Cargo.toml - + jq -r '.boards | to_entries | map(select(.value.tier == 1) | .key) | .[]' crates.json | while read dir; do + # Bump the BSP version + cargo set-version --manifest-path "boards/$dir/Cargo.toml" --bump ${{ github.event.inputs.bsp_bump }} + done - name: Generate patch shell: bash @@ -127,7 +103,12 @@ jobs: id: cpr uses: peter-evans/create-pull-request@v6 with: - commit-message: ${{ github.event.inputs.bump }} bump of crate versions + 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 From 8202f12cf222180b9709dde350f37db79bafb074 Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Wed, 4 Sep 2024 18:12:20 -0400 Subject: [PATCH 2/7] Update changelogs when bumping crates --- .github/workflows/bump-crates.yml | 17 ++++++++++-- .github/workflows/crate_version.py | 22 +++++++++++++++ .github/workflows/update_changelog.py | 39 +++++++++++++++++++++++++++ .gitignore | 1 + 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/crate_version.py create mode 100644 .github/workflows/update_changelog.py diff --git a/.github/workflows/bump-crates.yml b/.github/workflows/bump-crates.yml index 6bbbba99ee46..1a845cef70e3 100644 --- a/.github/workflows/bump-crates.yml +++ b/.github/workflows/bump-crates.yml @@ -29,6 +29,7 @@ jobs: steps: - name: Set up Rust run: | + sudo apt-get install python3-pip && pip install tomlkit rustup set profile minimal rustup override set stable - uses: actions/checkout@v4 @@ -49,9 +50,13 @@ jobs: for dir in pac/*/ ; do # Remove the trailing slash dir=${dir%/} + manifest="$dir/Cargo.toml" # Bump the PAC version - cargo set-version --manifest-path "$dir/Cargo.toml" --bump ${{ github.event.inputs.pac_bump }} + cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.pac_bump }} + + # Update the changelog + python3 .github/workflows/update_changelog.py $dir done - name: Update HAL deps @@ -67,6 +72,9 @@ jobs: # 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 + python3 .github/workflows/update_changelog.py hal/ + - name: Update BSP deps if: github.event.inputs.sync_bsp == 'yes' uses: ./.github/actions/sync-bsp-versions @@ -78,8 +86,13 @@ jobs: 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 "boards/$dir/Cargo.toml" --bump ${{ github.event.inputs.bsp_bump }} + cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.bsp_bump }} + + # Update the changelog + python3 .github/workflows/update_changelog.py "boards/$dir/" done - name: Generate patch diff --git a/.github/workflows/crate_version.py b/.github/workflows/crate_version.py new file mode 100644 index 000000000000..36d4a190977d --- /dev/null +++ b/.github/workflows/crate_version.py @@ -0,0 +1,22 @@ +import tomlkit +import sys +import argparse + +def get_crate_version(manifest_path): + with open(manifest_path, 'r', encoding='utf-8') as f: + cargo_toml = tomlkit.parse(f.read()) + + return cargo_toml["package"]["version"] + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Get crate version from a Cargo manifest file") + parser.add_argument('manifest_path', help="Path to the Cargo.toml manifest") + args = parser.parse_args() + + try: + version = get_crate_version(args.manifest_path) + print(version) + except (FileNotFoundError, KeyError): + sys.stderr.write("Error: Could not find the version in the specified Cargo.toml file.\n") + sys.exit(1) diff --git a/.github/workflows/update_changelog.py b/.github/workflows/update_changelog.py new file mode 100644 index 000000000000..8c65dc1bbe76 --- /dev/null +++ b/.github/workflows/update_changelog.py @@ -0,0 +1,39 @@ +from crate_version import get_crate_version +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") + + args = parser.parse_args() + + # Get the crate version from Cargo.toml + manifest_path = f'{args.crate_path}/Cargo.toml' + crate_version = get_crate_version(manifest_path) + + # Update the changelog + crate_changelog_path = f'{args.crate_path}/CHANGELOG.md' + update_changelog(crate_changelog_path, crate_version) diff --git a/.gitignore b/.gitignore index 6ae6b2d9b934..eaae0955026e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Cargo.lock **/.DS_Store *.svd.patched .vscode +__pycache__/ From c4669c3be292cc325d2b18bfef35d0e166cd2085 Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Wed, 4 Sep 2024 18:28:18 -0400 Subject: [PATCH 3/7] Revert PAC changelogs to the format the workflow expects --- pac/atsamd11c/CHANGELOG.md | 2 +- pac/atsamd11d/CHANGELOG.md | 2 +- pac/atsamd21e/CHANGELOG.md | 2 +- pac/atsamd21g/CHANGELOG.md | 2 +- pac/atsamd21j/CHANGELOG.md | 2 +- pac/atsamd51g/CHANGELOG.md | 2 +- pac/atsamd51j/CHANGELOG.md | 2 +- pac/atsamd51n/CHANGELOG.md | 2 +- pac/atsamd51p/CHANGELOG.md | 2 +- pac/atsame51g/CHANGELOG.md | 2 +- pac/atsame51j/CHANGELOG.md | 2 +- pac/atsame51n/CHANGELOG.md | 2 +- pac/atsame53j/CHANGELOG.md | 2 +- pac/atsame53n/CHANGELOG.md | 2 +- pac/atsame54n/CHANGELOG.md | 2 +- pac/atsame54p/CHANGELOG.md | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pac/atsamd11c/CHANGELOG.md b/pac/atsamd11c/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd11c/CHANGELOG.md +++ b/pac/atsamd11c/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsamd11d/CHANGELOG.md b/pac/atsamd11d/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd11d/CHANGELOG.md +++ b/pac/atsamd11d/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsamd21e/CHANGELOG.md b/pac/atsamd21e/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd21e/CHANGELOG.md +++ b/pac/atsamd21e/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsamd21g/CHANGELOG.md b/pac/atsamd21g/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd21g/CHANGELOG.md +++ b/pac/atsamd21g/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsamd21j/CHANGELOG.md b/pac/atsamd21j/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd21j/CHANGELOG.md +++ b/pac/atsamd21j/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsamd51g/CHANGELOG.md b/pac/atsamd51g/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd51g/CHANGELOG.md +++ b/pac/atsamd51g/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsamd51j/CHANGELOG.md b/pac/atsamd51j/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd51j/CHANGELOG.md +++ b/pac/atsamd51j/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsamd51n/CHANGELOG.md b/pac/atsamd51n/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd51n/CHANGELOG.md +++ b/pac/atsamd51n/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsamd51p/CHANGELOG.md b/pac/atsamd51p/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsamd51p/CHANGELOG.md +++ b/pac/atsamd51p/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsame51g/CHANGELOG.md b/pac/atsame51g/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsame51g/CHANGELOG.md +++ b/pac/atsame51g/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsame51j/CHANGELOG.md b/pac/atsame51j/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsame51j/CHANGELOG.md +++ b/pac/atsame51j/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsame51n/CHANGELOG.md b/pac/atsame51n/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsame51n/CHANGELOG.md +++ b/pac/atsame51n/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsame53j/CHANGELOG.md b/pac/atsame53j/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsame53j/CHANGELOG.md +++ b/pac/atsame53j/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsame53n/CHANGELOG.md b/pac/atsame53n/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsame53n/CHANGELOG.md +++ b/pac/atsame53n/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsame54n/CHANGELOG.md b/pac/atsame54n/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsame54n/CHANGELOG.md +++ b/pac/atsame54n/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` diff --git a/pac/atsame54p/CHANGELOG.md b/pac/atsame54p/CHANGELOG.md index cab3b33827ca..58d0438fa545 100644 --- a/pac/atsame54p/CHANGELOG.md +++ b/pac/atsame54p/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.14.0 +# Unreleased Changes - Upgrade PAC generated code to latest SVD and `svd2rust-0.34.1`: - All peripheral types are now `PascalCase` From 4d2bd7ea965d8e0b571c4406cae3ee59d7f23b09 Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Wed, 4 Sep 2024 21:42:04 -0400 Subject: [PATCH 4/7] Always sync dependencies between HAL, T1 BSPs and PACs --- .github/workflows/bump-crates.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/bump-crates.yml b/.github/workflows/bump-crates.yml index 1a845cef70e3..ea899df83fda 100644 --- a/.github/workflows/bump-crates.yml +++ b/.github/workflows/bump-crates.yml @@ -6,18 +6,10 @@ on: description: 'PAC version bump (none/patch/minor/major)' required: true default: 'none' - sync_hal: - description: 'Update PAC dep string in HAL crate (yes/no)' - required: true - default: 'yes' hal_bump: description: 'HAL version bump (none/patch/minor/major)' required: true default: 'none' - sync_bsp: - description: 'Update HAL dep string in T1 BSP crates (yes/no)' - required: true - default: 'yes' bsp_bump: description: 'T1 BSP version bump (none/patch/minor/major)' required: true @@ -60,7 +52,6 @@ jobs: done - name: Update HAL deps - if: github.event.inputs.sync_hal == 'yes' uses: ./.github/actions/sync-pac-versions - name: Bump HAL version @@ -76,7 +67,6 @@ jobs: python3 .github/workflows/update_changelog.py hal/ - name: Update BSP deps - if: github.event.inputs.sync_bsp == 'yes' uses: ./.github/actions/sync-bsp-versions - name: Bump BSP versions From 4639886a7a8427615c4db1c81f0598e9c1d6d162 Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Wed, 4 Sep 2024 21:42:23 -0400 Subject: [PATCH 5/7] Add a bump Tier 2 BSP workflow --- .github/workflows/bump-t2-bsp.yml | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/bump-t2-bsp.yml diff --git a/.github/workflows/bump-t2-bsp.yml b/.github/workflows/bump-t2-bsp.yml new file mode 100644 index 000000000000..9e22b509623e --- /dev/null +++ b/.github/workflows/bump-t2-bsp.yml @@ -0,0 +1,96 @@ +name: Bump crate versions +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: | + sudo apt-get install python3-pip && pip install tomlkit + 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 + python3 .github/workflows/update_changelog.py "boards/$bsp/" + 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.input.bsp_name }} (${{ github.event.inputs.bsp_bump }}) + committer: GitHub + author: atsamd-bot + signoff: false + branch: bump-${{ github.event.input.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 From e90e5007f397b661fd979c983cd6b1c8d151b7c3 Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Wed, 4 Sep 2024 22:00:32 -0400 Subject: [PATCH 6/7] Automatically tag HAL releases --- .github/workflows/release-crates.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/release-crates.yml b/.github/workflows/release-crates.yml index f769a97f252a..16ced13e0498 100644 --- a/.github/workflows/release-crates.yml +++ b/.github/workflows/release-crates.yml @@ -66,17 +66,27 @@ jobs: ) 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 + sudo apt-get install python3-pip && pip install tomlkit + # Force update of the registry cargo update || true cd "hal" && cargo publish --no-verify + version=$(python3 ../.github/workflows/crate_version.py Cargo.toml) + git tag -a "v${version}" -m "atsamd-hal release v${version}" + git push origin tag "v${version}" + - name: Release BSP crates if: github.event.inputs.release_bsp == 'yes' From 9922c40afa333919910665e5baf5d0606fe217eb Mon Sep 17 00:00:00 2001 From: Justin Beaurivage Date: Sun, 8 Sep 2024 21:07:57 -0400 Subject: [PATCH 7/7] Get crate version with cargo-metadata instead of python+tomlkit --- .github/workflows/bump-crates.yml | 10 ++++++---- .github/workflows/bump-t2-bsp.yml | 6 +++--- .github/workflows/crate_version.py | 22 ---------------------- .github/workflows/release-crates.yml | 4 +--- .github/workflows/update_changelog.py | 5 ++--- 5 files changed, 12 insertions(+), 35 deletions(-) delete mode 100644 .github/workflows/crate_version.py diff --git a/.github/workflows/bump-crates.yml b/.github/workflows/bump-crates.yml index ea899df83fda..44d183af37bd 100644 --- a/.github/workflows/bump-crates.yml +++ b/.github/workflows/bump-crates.yml @@ -21,7 +21,6 @@ jobs: steps: - name: Set up Rust run: | - sudo apt-get install python3-pip && pip install tomlkit rustup set profile minimal rustup override set stable - uses: actions/checkout@v4 @@ -48,7 +47,8 @@ jobs: cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.pac_bump }} # Update the changelog - python3 .github/workflows/update_changelog.py $dir + 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 @@ -64,7 +64,8 @@ jobs: cargo set-version --manifest-path "hal/Cargo.toml" --exclude atsamd-hal-macros --bump ${{ github.event.inputs.hal_bump }} # Update the changelog - python3 .github/workflows/update_changelog.py hal/ + 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 @@ -82,7 +83,8 @@ jobs: cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.bsp_bump }} # Update the changelog - python3 .github/workflows/update_changelog.py "boards/$dir/" + 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 diff --git a/.github/workflows/bump-t2-bsp.yml b/.github/workflows/bump-t2-bsp.yml index 9e22b509623e..f6ee6466d661 100644 --- a/.github/workflows/bump-t2-bsp.yml +++ b/.github/workflows/bump-t2-bsp.yml @@ -1,4 +1,4 @@ -name: Bump crate versions +name: Bump version of a single Tier 2 crate on: workflow_dispatch: inputs: @@ -16,7 +16,6 @@ jobs: steps: - name: Set up Rust run: | - sudo apt-get install python3-pip && pip install tomlkit rustup set profile minimal rustup override set stable - uses: actions/checkout@v4 @@ -47,7 +46,8 @@ jobs: cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.bsp_bump }} # Update the changelog - python3 .github/workflows/update_changelog.py "boards/$bsp/" + 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 diff --git a/.github/workflows/crate_version.py b/.github/workflows/crate_version.py deleted file mode 100644 index 36d4a190977d..000000000000 --- a/.github/workflows/crate_version.py +++ /dev/null @@ -1,22 +0,0 @@ -import tomlkit -import sys -import argparse - -def get_crate_version(manifest_path): - with open(manifest_path, 'r', encoding='utf-8') as f: - cargo_toml = tomlkit.parse(f.read()) - - return cargo_toml["package"]["version"] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Get crate version from a Cargo manifest file") - parser.add_argument('manifest_path', help="Path to the Cargo.toml manifest") - args = parser.parse_args() - - try: - version = get_crate_version(args.manifest_path) - print(version) - except (FileNotFoundError, KeyError): - sys.stderr.write("Error: Could not find the version in the specified Cargo.toml file.\n") - sys.exit(1) diff --git a/.github/workflows/release-crates.yml b/.github/workflows/release-crates.yml index 16ced13e0498..bd68114d7420 100644 --- a/.github/workflows/release-crates.yml +++ b/.github/workflows/release-crates.yml @@ -76,14 +76,12 @@ jobs: run: | set -ex - sudo apt-get install python3-pip && pip install tomlkit - # Force update of the registry cargo update || true cd "hal" && cargo publish --no-verify - version=$(python3 ../.github/workflows/crate_version.py Cargo.toml) + version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') git tag -a "v${version}" -m "atsamd-hal release v${version}" git push origin tag "v${version}" diff --git a/.github/workflows/update_changelog.py b/.github/workflows/update_changelog.py index 8c65dc1bbe76..d9cf7b20c624 100644 --- a/.github/workflows/update_changelog.py +++ b/.github/workflows/update_changelog.py @@ -1,4 +1,3 @@ -from crate_version import get_crate_version import argparse import re import sys @@ -27,13 +26,13 @@ def update_changelog(changelog_path, 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' - crate_version = get_crate_version(manifest_path) # Update the changelog crate_changelog_path = f'{args.crate_path}/CHANGELOG.md' - update_changelog(crate_changelog_path, crate_version) + update_changelog(crate_changelog_path, args.crate_version)