NRF upmerge #62
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: NRF upmerge | |
on: | |
schedule: | |
- cron: "0 0 * * 0" | |
workflow_dispatch: | |
jobs: | |
change_nrf_revision: | |
name: Create PR with NRF upmerge | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
GH_TOKEN: ${{secrets.NCS_GITHUB_TOKEN}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for all branches and tags | |
path: sidewalk | |
- name: Checkout nrf | |
uses: actions/checkout@v4 | |
with: | |
repository: nrfconnect/sdk-nrf | |
path: nrf | |
ref: main | |
fetch-depth: 0 | |
- name: Configure Git | |
run: | | |
git config --global user.name 'Sidewalk Team' | |
git config --global user.email 'sidewalk@nordicsemi.no' | |
- name: Create or update PR | |
run: | | |
# Set variables | |
BRANCH_NAME="nrf-upmerge" | |
PR_TITLE="manifest: Update NRF" | |
PR_BODY="Automated weekly update PR created by GitHub Actions" | |
cd sidewalk | |
git fetch --all | |
# Check if PR branch exists | |
if git show-ref --verify --quiet refs/remotes/origin/$BRANCH_NAME; then | |
echo "Branch $BRANCH_NAME exists, checking PR status..." | |
# Check if PR exists and is open | |
PR_NUMBER=$(gh pr list --head $BRANCH_NAME --json number --jq '.[0].number' 2>/dev/null || echo "") | |
if [ -n "$PR_NUMBER" ]; then | |
echo "PR #$PR_NUMBER exists and is open" | |
# Check if PR is merged | |
PR_MERGED=$(gh pr view $PR_NUMBER --json merged --jq '.merged') | |
if [ "$PR_MERGED" = "true" ]; then | |
echo "PR is merged, creating new branch" | |
# Delete old branch | |
git push origin --delete $BRANCH_NAME | |
# Create new branch | |
git checkout -b $BRANCH_NAME | |
else | |
echo "PR is open, updating existing branch" | |
git checkout $BRANCH_NAME | |
git pull origin $BRANCH_NAME | |
fi | |
else | |
echo "PR doesn't exist, updating existing branch" | |
git checkout $BRANCH_NAME | |
git pull origin $BRANCH_NAME | |
fi | |
else | |
echo "Creating new branch $BRANCH_NAME" | |
git checkout -b $BRANCH_NAME | |
fi | |
# Run your update script here | |
python3 -m pip install -r scripts/ci/requirements.txt | |
nrf_hash="$(git -C ../nrf rev-parse HEAD)" | |
echo "nrf hash = ${nrf_hash}" | |
python3 scripts/ci/replace_nrf_revision_in_west.py -r $nrf_hash west.yml | |
git status | |
git diff | |
# Check if there are changes to commit | |
if git status --porcelain | grep -q '^[ M][MADRCU]'; then | |
echo "Changes detected, committing and pushing" | |
# Add and commit changes | |
git add . | |
git commit \ | |
-m "manifest: Update NRF revision in west.yml" \ | |
-m ""\ | |
-m "Weekly update: $(date +%Y-%m-%d)" --signoff | |
# Push changes | |
git push origin $BRANCH_NAME | |
# Create or update PR | |
if [ -n "$PR_NUMBER" ]; then | |
echo "Updating existing PR #$PR_NUMBER" | |
else | |
echo "Creating new PR" | |
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main | |
fi | |
else | |
echo "No changes detected" | |
fi |