diff --git a/.github/workflows/protect-default-branch.yaml b/.github/workflows/protect-default-branch.yaml new file mode 100644 index 00000000..61f85f45 --- /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-candidate.yaml b/.github/workflows/release-candidate.yaml index 1b8888a6..98bc79b9 100644 --- a/.github/workflows/release-candidate.yaml +++ b/.github/workflows/release-candidate.yaml @@ -38,7 +38,7 @@ jobs: repository_owner: husarion repository_name: ${{ matrix.repo }} new_branch_name: ${{ env.RC_BRANCH_NAME }} - new_branch_ref: ros2 + new_branch_ref: ros2-devel access_token: ${{ secrets.GH_PAT}} update_tags_in_compose: @@ -58,7 +58,7 @@ jobs: wait_interval: 10 client_payload: | { - "target_branch": "${{ env.RC_BRANCH_NAME }}", + "branch_name": "${{ env.RC_BRANCH_NAME }}", "image_tag": "humble-${{ env.RC_BRANCH_NAME }}" } diff --git a/.github/workflows/release-project.yaml b/.github/workflows/release-project.yaml index 132de2de..48b98d95 100644 --- a/.github/workflows/release-project.yaml +++ b/.github/workflows/release-project.yaml @@ -6,15 +6,15 @@ on: inputs: version: description: Release version, must match release candidate version. IMPORTANT - required format - `X.X.X`, eg `2.0.1`. + `X.X.X`, (e.g. `2.0.1`). required: true date: description: Release date stamp, must match release candidate date. IMPORTANT - required format - `YYYYMMDD`, eg `20240430`. + `YYYYMMDD`, (e.g. `20240430`). required: true release_name: description: Name of the release to be created. Version in the first place is recommended (e.g. - `2.0.0-alpha`). + `2.0.1-alpha`). required: true automatic_mode: type: boolean @@ -45,7 +45,7 @@ jobs: wait_interval: 10 client_payload: | { - "target_branch": "${{ env.RC_BRANCH_NAME }}", + "release_candidate": "${{ env.RC_BRANCH_NAME }}", "version": "${{ github.event.inputs.version }}", "release_name": "${{ github.event.inputs.release_name }}", "automatic_mode": "${{ github.event.inputs.automatic_mode }}", @@ -63,23 +63,44 @@ jobs: with: owner: husarion repo: panther_ros - github_token: ${{ secrets.GITHUB_TOKEN }} # Use the default GITHUB_TOKEN for local repository + github_token: ${{ secrets.GITHUB_TOKEN }} # Use the default GITHUB_TOKEN for local repository workflow_file_name: release-repository.yaml ref: ${{ env.RC_BRANCH_NAME }} wait_interval: 10 client_payload: | { - "target_branch": "${{ env.RC_BRANCH_NAME }}", + "release_candidate": "${{ env.RC_BRANCH_NAME }}", "version": "${{ github.event.inputs.version }}", "release_name": "${{ github.event.inputs.release_name }}", "automatic_mode": "${{ github.event.inputs.automatic_mode }}", "prerelease": "${{ github.event.inputs.prerelease }}" } + rebuild_and_push_docker_images: + name: Rebuild panther docker images with new version + runs-on: ubuntu-22.04 + needs: + - release_panther_ros + steps: + - name: Trigger repository build workflow + uses: convictional/trigger-workflow-and-wait@v1.6.1 + with: + owner: husarion + repo: panther-docker + github_token: ${{ secrets.GH_PAT }} + workflow_file_name: ros-docker-image.yaml + ref: ${{ env.RC_BRANCH_NAME }} + wait_interval: 10 + client_payload: | + { + "build_type": "development", + "target_distro": "humble" + } + release_panther_docker: name: Release panther-docker repository needs: - - release_panther_ros + - rebuild_and_push_docker_images runs-on: ubuntu-22.04 steps: - name: Trigger repository release workflow @@ -93,7 +114,7 @@ jobs: wait_interval: 10 client_payload: | { - "target_branch": "${{ env.RC_BRANCH_NAME }}", + "release_candidate": "${{ env.RC_BRANCH_NAME }}", "version": "${{ github.event.inputs.version }}", "date": "${{ github.event.inputs.date }}", "release_name": "${{ github.event.inputs.release_name }}", @@ -101,8 +122,8 @@ jobs: "prerelease": "${{ github.event.inputs.prerelease }}" } - build_and_push_docker_images: - name: Build panther docker images + tag_docker_images: + name: Tag panther docker images as stable if: ${{ fromJSON(github.event.inputs.automatic_mode) == true }} needs: - release_panther_docker @@ -143,7 +164,7 @@ jobs: wait_interval: 10 client_payload: | { - "target_branch": "${{ env.RC_BRANCH_NAME }}", + "release_candidate": "${{ env.RC_BRANCH_NAME }}", "version": "${{ github.event.inputs.version }}", "release_name": "${{ github.event.inputs.release_name }}", "automatic_mode": "${{ github.event.inputs.automatic_mode }}", diff --git a/.github/workflows/release-repository.yaml b/.github/workflows/release-repository.yaml index ed1b53d3..a5375e55 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 and package versioning). @@ -30,14 +30,15 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} MAIN_BRANCH: ros2 + DEVEL_BRANCH: ros2-devel 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: Create release candidate - id: create_release_candidate + - name: Catkin release + id: catkin_release uses: at-wat/catkin-release-action@v1 with: version: ${{ github.event.inputs.version }} @@ -45,49 +46,49 @@ jobs: git_email: action-bot@action-bot.com github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Create pull request + - name: Catkin release - create PR run: | gh pr create \ - --base ${{ github.event.inputs.target_branch }} \ - --head ${{ steps.create_release_candidate.outputs.created_branch }} \ - --title "Release ${{ steps.create_release_candidate.outputs.version}}" \ + --base ${{ github.event.inputs.release_candidate }} \ + --head ${{ steps.catkin_release.outputs.created_branch }} \ + --title "Release ${{ steps.catkin_release.outputs.version}}" \ --body "This PR incorporates package(s) version and changelog update." - - name: Merge pull request + - name: Catkin release - merge PR if: ${{ fromJSON(github.event.inputs.automatic_mode) == true }} run: | - gh pr merge ${{ steps.create_release_candidate.outputs.created_branch }} \ + gh pr merge ${{ steps.catkin_release.outputs.created_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(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(inputs.automatic_mode) == true }} run: | gh pr create \ --base ${{ env.MAIN_BRANCH }} \ - --head ${{ github.event.inputs.target_branch }} \ - --title "Release ${{ steps.create_release_candidate.outputs.version}} to ${{ env.MAIN_BRANCH }}" \ + --head ${{ github.event.inputs.release_candidate }} \ + --title "Release ${{ steps.catkin_release.outputs.version}} to ${{ env.MAIN_BRANCH }}" \ --body "This PR incorporates package(s) version and changelog update." - - 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(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) == true}} run: | - gh release create ${{ steps.create_release_candidate.outputs.version }} \ + gh release create ${{ steps.catkin_release.outputs.version }} \ --target ${{ env.MAIN_BRANCH }} \ --title ${{ github.event.inputs.release_name }} \ --generate-notes \ @@ -97,7 +98,19 @@ jobs: if: ${{ fromJSON(github.event.inputs.automatic_mode) == true && fromJSON(github.event.inputs.prerelease) == false}} run: | - gh release create ${{ steps.create_release_candidate.outputs.version }} \ + gh release create ${{ steps.catkin_release.outputs.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 }}