From c5309fa75a6262bd42a6ff1cc83ec91a5fad96f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Irzyk?= <108666440+pawelirh@users.noreply.github.com> Date: Thu, 6 Jun 2024 12:27:51 +0200 Subject: [PATCH 1/4] Ros2 improve release process (#71) * Change branch naming * Add devel branch update * Add branch protection workflow * Add coderabbit config --- .coderabbit.yaml | 17 ++++++ .github/workflows/protect-default-branch.yaml | 23 ++++++++ .github/workflows/release-repository.yaml | 57 ++++++++++++------- .github/workflows/update-tags-in-compose.yaml | 4 +- 4 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 .coderabbit.yaml create mode 100644 .github/workflows/protect-default-branch.yaml diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 0000000..51c85f2 --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,17 @@ +# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json +language: "en-US" +early_access: false +reviews: + profile: "chill" + request_changes_workflow: false + high_level_summary: true + poem: false + review_status: true + collapse_walkthrough: false + auto_review: + enabled: true + drafts: false + base_branches: + - "ros2-devel" +chat: + auto_reply: true \ No newline at end of file diff --git a/.github/workflows/protect-default-branch.yaml b/.github/workflows/protect-default-branch.yaml new file mode 100644 index 0000000..61f85f4 --- /dev/null +++ b/.github/workflows/protect-default-branch.yaml @@ -0,0 +1,23 @@ +name: Validate PR head branch +on: + pull_request: + branches: + - "ros2" + +jobs: + check-head-branch: + runs-on: ubuntu-latest + steps: + - name: Check allowed branches + run: | + pattern="^[0-9]+\.[0-9]+\.[0-9]+-[0-9]{8}$" # This regex matches the X.X.X-YYYYMMDD pattern + if [[ "${{ github.head_ref }}" == *"hotfix"* ]]; then + echo "PR from a branch containing 'hotfix' is allowed." + exit 0 + elif [[ "${{ github.head_ref }}" =~ $pattern ]]; then + echo "PR from a branch matching X.X.X-YYYYMMDD pattern is allowed." + exit 0 + else + echo "PRs must come from branches containing 'hotfix' phrase or matching X.X.X-YYYYMMDD pattern." + exit 1 + fi \ No newline at end of file diff --git a/.github/workflows/release-repository.yaml b/.github/workflows/release-repository.yaml index 695e36a..a841e65 100644 --- a/.github/workflows/release-repository.yaml +++ b/.github/workflows/release-repository.yaml @@ -4,8 +4,8 @@ name: Release repository on: workflow_dispatch: inputs: - target_branch: - description: Target branch for the release. + release_candidate: + description: Branch name of the release candidate. required: true version: description: New version (used for tag). @@ -14,7 +14,8 @@ on: description: Date stamp of the image to be used in the compose files. required: true release_name: - description: Name of the release to be created. Version in the first place is recommended (e.g. + description: + Name of the release to be created. Version in the first place is recommended (e.g. `2.0.0-alpha`). required: true automatic_mode: @@ -33,13 +34,14 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_BRANCH: release-${{ github.event.inputs.version }} - DOCKER_IMAGE_TAG: humble-${{ github.event.inputs.version }}-${{ github.event.inputs.date }}-stable MAIN_BRANCH: ros2 + DEVEL_BRANCH: ros2-devel + DOCKER_IMAGE_TAG: humble-${{ github.event.inputs.version }}-${{ github.event.inputs.date }}-stable steps: - - name: Checkout + - name: Checkout to rc branch uses: actions/checkout@v4 with: - ref: ${{ github.event.inputs.target_branch }} + ref: ${{ github.event.inputs.release_candidate }} - name: Update docker image version uses: mikefarah/yq@v4.43.1 @@ -56,46 +58,50 @@ jobs: author_email: action-bot@action-bot.com new_branch: ${{ env.RELEASE_BRANCH }} - - name: Create pull request + - name: Create PR run: | gh pr create \ - --base ${{ github.event.inputs.target_branch }} \ + --base ${{ github.event.inputs.release_candidate }} \ --head $RELEASE_BRANCH \ --title "Release ${{ github.event.inputs.version }}" \ --body "This PR incorporates tag(s) update in docker compose files." - - name: Merge pull request + - name: Merge PR if: ${{ fromJSON(github.event.inputs.automatic_mode) == true }} run: | gh pr merge $RELEASE_BRANCH \ --merge --delete-branch - - name: Checkout to main - if: ${{ github.event.inputs.target_branch != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) + - name: Checkout to main branch + if: + ${{ github.event.inputs.release_candidate != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) == true }} uses: actions/checkout@v4 with: ref: ${{ env.MAIN_BRANCH }} - - name: Create pull request to main - if: ${{ github.event.inputs.target_branch != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) + - name: Create PR to main branch + if: + ${{ github.event.inputs.release_candidate != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) == true }} run: | gh pr create \ --base ${{ env.MAIN_BRANCH }} \ - --head ${{ github.event.inputs.target_branch }} \ + --head ${{ github.event.inputs.release_candidate }} \ --title "Release ${{ steps.create_release_candidate.outputs.version}} to ${{ env.MAIN_BRANCH }}" \ --body "This PR incorporates tag(s) update in docker compose files." - - name: Merge pull request to main - if: ${{ github.event.inputs.target_branch != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) + - name: Merge PR to main branch + if: + ${{ github.event.inputs.release_candidate != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) == true }} run: | - gh pr merge ${{ github.event.inputs.target_branch }} \ + gh pr merge ${{ github.event.inputs.release_candidate }} \ --merge --delete-branch - name: Create prerelease - if: ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) + if: + ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) == true}} run: | gh release create ${{ github.event.inputs.version }} \ @@ -105,10 +111,23 @@ jobs: --prerelease - name: Create release - if: ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) + if: + ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) == false}} run: | gh release create ${{ github.event.inputs.version }} \ --target ${{ env.MAIN_BRANCH }} \ --title ${{ github.event.inputs.release_name }} \ --generate-notes + + - name: Checkout to devel branch + if: ${{ env.DEVEL_BRANCH != env.MAIN_BRANCH && fromJSON(inputs.automatic_mode) == true }} + uses: actions/checkout@v4 + with: + ref: ${{ env.DEVEL_BRANCH }} + + - name: Update devel branch + if: ${{ env.DEVEL_BRANCH != env.MAIN_BRANCH && fromJSON(inputs.automatic_mode) == true }} + run: | + git pull origin ${{ env.MAIN_BRANCH }} + git push origin ${{ env.DEVEL_BRANCH }} \ No newline at end of file diff --git a/.github/workflows/update-tags-in-compose.yaml b/.github/workflows/update-tags-in-compose.yaml index a7e1464..2a42bba 100644 --- a/.github/workflows/update-tags-in-compose.yaml +++ b/.github/workflows/update-tags-in-compose.yaml @@ -4,7 +4,7 @@ name: Update tags in compose files on: workflow_dispatch: inputs: - target_branch: + branch_name: description: Target branch for the update. required: true image_tag: @@ -21,7 +21,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - ref: ${{ github.event.inputs.target_branch }} + ref: ${{ github.event.inputs.branch_name }} - name: Update docker image tag uses: mikefarah/yq@v4.43.1 From af3e8c4eefbf25bf57beff0185a71f5ca79eeae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Irzyk?= <108666440+pawelirh@users.noreply.github.com> Date: Thu, 6 Jun 2024 13:47:43 +0200 Subject: [PATCH 2/4] Remove stable tagging and update workflow (#72) --- .github/workflows/release-repository.yaml | 82 +++++++---------------- 1 file changed, 25 insertions(+), 57 deletions(-) diff --git a/.github/workflows/release-repository.yaml b/.github/workflows/release-repository.yaml index a841e65..ac6e7e7 100644 --- a/.github/workflows/release-repository.yaml +++ b/.github/workflows/release-repository.yaml @@ -10,9 +10,6 @@ on: version: description: New version (used for tag). required: true - date: - description: Date stamp of the image to be used in the compose files. - required: true release_name: description: Name of the release to be created. Version in the first place is recommended (e.g. @@ -33,76 +30,49 @@ jobs: runs-on: ubuntu-22.04 env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_BRANCH: release-${{ github.event.inputs.version }} MAIN_BRANCH: ros2 DEVEL_BRANCH: ros2-devel - DOCKER_IMAGE_TAG: humble-${{ github.event.inputs.version }}-${{ github.event.inputs.date }}-stable steps: - - name: Checkout to rc branch - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.release_candidate }} - - - name: Update docker image version - uses: mikefarah/yq@v4.43.1 - with: - cmd: | - yq -i '.services.panther_ros.image = "husarion/panther:${{ env.DOCKER_IMAGE_TAG }}" | (... | select(tag == "!!merge")) tag = ""' demo/compose.minimal-setup.yaml - yq -i '.services.panther_gazebo.image = "husarion/panther-gazebo:${{ env.DOCKER_IMAGE_TAG }}" | (... | select(tag == "!!merge")) tag = ""' demo/compose.simulation.yaml - - - name: Commit changes to release branch - uses: EndBug/add-and-commit@v9 - with: - message: Update docker image version - author_name: action-bot - author_email: action-bot@action-bot.com - new_branch: ${{ env.RELEASE_BRANCH }} - - - name: Create PR - run: | - gh pr create \ - --base ${{ github.event.inputs.release_candidate }} \ - --head $RELEASE_BRANCH \ - --title "Release ${{ github.event.inputs.version }}" \ - --body "This PR incorporates tag(s) update in docker compose files." - - - name: Merge PR - if: ${{ fromJSON(github.event.inputs.automatic_mode) == true }} - run: | - gh pr merge $RELEASE_BRANCH \ - --merge --delete-branch - - name: Checkout to main branch - if: - ${{ github.event.inputs.release_candidate != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) - == true }} + if: ${{ github.event.inputs.release_candidate != env.MAIN_BRANCH }} uses: actions/checkout@v4 with: ref: ${{ env.MAIN_BRANCH }} + fetch-depth: 0 + + - name: Get git diff between main and release candidate + id: git_diff + run: | + git fetch origin ${{ github.event.inputs.release_candidate }}:${{ github.event.inputs.release_candidate }} + DIFF=$(git diff --name-only ${{ github.event.inputs.release_candidate }}) # Change to "master.." to diff against last common commit + if [ -z "$DIFF" ]; then + echo "DIFF=false" >> $GITHUB_ENV + else + echo "DIFF=true" >> $GITHUB_ENV + fi - name: Create PR to main branch - if: - ${{ github.event.inputs.release_candidate != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) - == true }} + if: ${{ github.event.inputs.release_candidate != env.MAIN_BRANCH && env.DIFF == 'true' }} run: | gh pr create \ --base ${{ env.MAIN_BRANCH }} \ --head ${{ github.event.inputs.release_candidate }} \ - --title "Release ${{ steps.create_release_candidate.outputs.version}} to ${{ env.MAIN_BRANCH }}" \ - --body "This PR incorporates tag(s) update in docker compose files." + --title "Release ${{ github.event.inputs.version}} to ${{ env.MAIN_BRANCH }}" \ + --body "This PR incorporates release updates." - name: Merge PR to main branch - if: - ${{ github.event.inputs.release_candidate != env.MAIN_BRANCH && fromJSON(github.event.inputs.automatic_mode) - == true }} + if: ${{ fromJSON(github.event.inputs.automatic_mode) == true && github.event.inputs.release_candidate != env.MAIN_BRANCH && env.DIFF == 'true' }} run: | gh pr merge ${{ github.event.inputs.release_candidate }} \ --merge --delete-branch + - name: Delete branch + if: ${{ fromJSON(github.event.inputs.automatic_mode) == true && github.event.inputs.release_candidate != env.MAIN_BRANCH && env.DIFF == 'false' }} + run: | + git push origin --delete ${{ github.event.inputs.release_candidate }} + - name: Create prerelease - if: - ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) - == true}} + if: ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) == true}} run: | gh release create ${{ github.event.inputs.version }} \ --target ${{ env.MAIN_BRANCH }} \ @@ -111,9 +81,7 @@ jobs: --prerelease - name: Create release - if: - ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) - == false}} + if: ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) == false}} run: | gh release create ${{ github.event.inputs.version }} \ --target ${{ env.MAIN_BRANCH }} \ @@ -130,4 +98,4 @@ jobs: if: ${{ env.DEVEL_BRANCH != env.MAIN_BRANCH && fromJSON(inputs.automatic_mode) == true }} run: | git pull origin ${{ env.MAIN_BRANCH }} - git push origin ${{ env.DEVEL_BRANCH }} \ No newline at end of file + git push origin ${{ env.DEVEL_BRANCH }} From 45e1c3a55e38380df7d93aaa8f6aa86ae65a9c1a Mon Sep 17 00:00:00 2001 From: action-bot Date: Thu, 6 Jun 2024 11:51:42 +0000 Subject: [PATCH 3/4] Update docker image tag --- demo/compose.minimal-setup.yaml | 2 +- demo/compose.simulation.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/compose.minimal-setup.yaml b/demo/compose.minimal-setup.yaml index b589d69..dc8f77a 100644 --- a/demo/compose.minimal-setup.yaml +++ b/demo/compose.minimal-setup.yaml @@ -7,7 +7,7 @@ x-common-config: &common-config - ROS_DOMAIN_ID=${ROS_DOMAIN_ID:-0} services: panther_ros: - image: husarion/panther:humble-2.0.2-20240605-stable + image: husarion/panther:humble-2.0.3-20240606 container_name: panther_ros <<: *common-config devices: diff --git a/demo/compose.simulation.yaml b/demo/compose.simulation.yaml index 047f76e..fc0dde4 100644 --- a/demo/compose.simulation.yaml +++ b/demo/compose.simulation.yaml @@ -11,7 +11,7 @@ x-gpu-config: &gpu-config env_file: .env.gpu services: panther_gazebo: - image: husarion/panther-gazebo:humble-2.0.2-20240605-stable + image: husarion/panther-gazebo:humble-2.0.3-20240606 container_name: panther_gazebo <<: - *common-config From c4f6ee485718660c51a75bf52f6311dda47475c0 Mon Sep 17 00:00:00 2001 From: pawelirh Date: Thu, 6 Jun 2024 15:19:40 +0200 Subject: [PATCH 4/4] Hotfix - update devel branch after release --- .github/workflows/release-repository.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release-repository.yaml b/.github/workflows/release-repository.yaml index ac6e7e7..2e7e4e2 100644 --- a/.github/workflows/release-repository.yaml +++ b/.github/workflows/release-repository.yaml @@ -93,6 +93,7 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ env.DEVEL_BRANCH }} + fetch-depth: 0 - name: Update devel branch if: ${{ env.DEVEL_BRANCH != env.MAIN_BRANCH && fromJSON(inputs.automatic_mode) == true }}