From 28382905efa737c688dba329bfd4f14b7dafcd7d Mon Sep 17 00:00:00 2001 From: Hiroki OTA Date: Mon, 18 Mar 2024 15:56:29 +0900 Subject: [PATCH] feat(ci): add sync-tier4-upstream-up-to-tag (#347) * feat(ci): add sync-tier4-upstream-up-to-tag * style(pre-commit): autofix * delete quote --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../sync-tier4-upstream-up-to-tag.yaml | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/sync-tier4-upstream-up-to-tag.yaml diff --git a/.github/workflows/sync-tier4-upstream-up-to-tag.yaml b/.github/workflows/sync-tier4-upstream-up-to-tag.yaml new file mode 100644 index 0000000000..f85b58a2fa --- /dev/null +++ b/.github/workflows/sync-tier4-upstream-up-to-tag.yaml @@ -0,0 +1,92 @@ +# This workflow is intended for the use in the repositories created by forking tier4/autoware_launch. +name: sync-tier4-upstream-up-to-tag + +on: + workflow_dispatch: + inputs: + sync-target-tag: + description: sync target tag like v0.24.0 + required: true + type: string + default: "" + +jobs: + sync-tier4-upstream-up-to-tag: + runs-on: ubuntu-latest + env: + BASE_BRANCH: tier4/main + SYNC_TARGET_REPOSITORY: https://github.com/tier4/autoware_launch.git + steps: + - name: Generate token + id: generate-token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.PRIVATE_KEY }} + + - name: Check out repository + uses: actions/checkout@v4 + with: + ref: ${{ env.BASE_BRANCH }} + fetch-depth: 0 + + - name: Set git config + uses: autowarefoundation/autoware-github-actions/set-git-config@v1 + with: + token: ${{ steps.generate-token.outputs.token }} + + - name: Sync tag + run: | + git remote add sync-target ${{ env.SYNC_TARGET_REPOSITORY }} + git fetch -pPtf --all + git reset --hard "${{ inputs.sync-target-tag }}" + git remote rm sync-target + shell: bash + + - name: Generate changelog + id: generate-changelog + uses: autowarefoundation/autoware-github-actions/generate-changelog@v1 + with: + git-cliff-args: origin/${{ env.BASE_BRANCH }}..HEAD + + - name: Replace PR number to URL + id: replace-pr-number-to-url + run: | + # Output multiline strings: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string + changelog=$(echo "$CHANGELOG" | sed -r "s|\(#([0-9]+)\)|("${REPO_URL%.git}"/pull/\1)|g") + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "changelog<<$EOF" >> $GITHUB_OUTPUT + echo "$changelog" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + env: + CHANGELOG: ${{ steps.generate-changelog.outputs.changelog }} + REPO_URL: ${{ env.SYNC_TARGET_REPOSITORY }} + shell: bash + + - name: Create PR + id: create-pr + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ steps.generate-token.outputs.token }} + base: ${{ env.BASE_BRANCH }} + branch: sync-tier4-upstream-${{ inputs.sync-target-tag }} + title: "chore: sync upstream up to ${{ inputs.sync-target-tag }}" + body: ${{ steps.replace-pr-number-to-url.outputs.changelog }} + labels: | + bot + sync-tier4-upstream + author: github-actions + signoff: true + delete-branch: true + + - name: Check outputs + run: | + echo "Pull Request Number - ${{ steps.create-pr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.create-pr.outputs.pull-request-url }}" + + - name: Enable auto-merge + if: ${{ steps.create-pr.outputs.pull-request-operation == 'created' }} + run: gh pr merge --merge --auto "${{ steps.create-pr.outputs.pull-request-number }}" + shell: bash + env: + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}