Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve release workflows #757

Merged
merged 7 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/sync-bsp-versions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/actions/sync-pac-versions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 30 additions & 44 deletions .github/workflows/bump-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,31 +30,28 @@ 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'
shell: bash
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%/}
manifest="$dir/Cargo.toml"

# 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
# Bump the PAC version
cargo set-version --manifest-path $manifest --bump ${{ github.event.inputs.pac_bump }}

echo "y" | cargo ws2 [ "${pacs}" ] publish ${{ github.event.inputs.pac_bump }}

git checkout Cargo.toml
# 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
if: github.event.inputs.sync_hal == 'yes'
uses: ./.github/actions/sync-pac-versions

- name: Bump HAL version
Expand All @@ -71,19 +60,14 @@ 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 }}
# Bump the HAL version
cargo set-version --manifest-path "hal/Cargo.toml" --exclude atsamd-hal-macros --bump ${{ github.event.inputs.hal_bump }}

git checkout Cargo.toml
# 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
if: github.event.inputs.sync_bsp == 'yes'
uses: ./.github/actions/sync-bsp-versions

- name: Bump BSP versions
Expand All @@ -92,19 +76,16 @@ jobs:
run: |
set -ex

T1_BOARDS=$(cat crates.json | jq -Mr -c '[.boards | to_entries | map([.key, .value.tier]) | .[] | select(.[1] == 1) | .[0]] | join(" ")')
jq -r '.boards | to_entries | map(select(.value.tier == 1) | .key) | .[]' crates.json | while read dir; do
manifest="boards/$dir/Cargo.toml"

# 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
# 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
Expand All @@ -127,7 +108,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 <[email protected]>
author: atsamd-bot <[email protected]>
signoff: false
Expand Down
96 changes: 96 additions & 0 deletions .github/workflows/bump-t2-bsp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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.input.bsp_name }} (${{ github.event.inputs.bsp_bump }})
committer: GitHub <[email protected]>
author: atsamd-bot <[email protected]>
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
8 changes: 8 additions & 0 deletions .github/workflows/release-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ 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
Expand All @@ -77,6 +81,10 @@ jobs:

cd "hal" && cargo publish --no-verify

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}"


- name: Release BSP crates
if: github.event.inputs.release_bsp == 'yes'
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/update_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Cargo.lock
**/.DS_Store
*.svd.patched
.vscode
__pycache__/
2 changes: 1 addition & 1 deletion pac/atsamd11c/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsamd11d/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsamd21e/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsamd21g/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsamd21j/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsamd51g/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsamd51j/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsamd51n/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsamd51p/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsame51g/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsame51j/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsame51n/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsame53j/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsame53n/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pac/atsame54n/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
Loading
Loading