|
| 1 | +# This workflow is intended for the use in the repositories created by forking tier4/autoware_launch. |
| 2 | +name: sync-tier4-upstream-up-to-tag |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + sync-target-tag: |
| 8 | + description: sync target tag like v0.24.0 |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + default: "" |
| 12 | + |
| 13 | +jobs: |
| 14 | + sync-tier4-upstream-up-to-tag: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + BASE_BRANCH: tier4/main |
| 18 | + SYNC_TARGET_REPOSITORY: https://github.com/tier4/autoware_launch.git |
| 19 | + steps: |
| 20 | + - name: Generate token |
| 21 | + id: generate-token |
| 22 | + uses: tibdex/github-app-token@v1 |
| 23 | + with: |
| 24 | + app_id: ${{ secrets.APP_ID }} |
| 25 | + private_key: ${{ secrets.PRIVATE_KEY }} |
| 26 | + |
| 27 | + - name: Check out repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + ref: ${{ env.BASE_BRANCH }} |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Set git config |
| 34 | + uses: autowarefoundation/autoware-github-actions/set-git-config@v1 |
| 35 | + with: |
| 36 | + token: ${{ steps.generate-token.outputs.token }} |
| 37 | + |
| 38 | + - name: Sync tag |
| 39 | + run: | |
| 40 | + git remote add sync-target ${{ env.SYNC_TARGET_REPOSITORY }} |
| 41 | + git fetch -pPtf --all |
| 42 | + git reset --hard "${{ inputs.sync-target-tag }}" |
| 43 | + git remote rm sync-target |
| 44 | + shell: bash |
| 45 | + |
| 46 | + - name: Generate changelog |
| 47 | + id: generate-changelog |
| 48 | + uses: autowarefoundation/autoware-github-actions/generate-changelog@v1 |
| 49 | + with: |
| 50 | + git-cliff-args: origin/${{ env.BASE_BRANCH }}..HEAD |
| 51 | + |
| 52 | + - name: Replace PR number to URL |
| 53 | + id: replace-pr-number-to-url |
| 54 | + run: | |
| 55 | + # Output multiline strings: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string |
| 56 | + changelog=$(echo "$CHANGELOG" | sed -r "s|\(#([0-9]+)\)|("${REPO_URL%.git}"/pull/\1)|g") |
| 57 | + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) |
| 58 | + echo "changelog<<$EOF" >> $GITHUB_OUTPUT |
| 59 | + echo "$changelog" >> $GITHUB_OUTPUT |
| 60 | + echo "$EOF" >> $GITHUB_OUTPUT |
| 61 | + env: |
| 62 | + CHANGELOG: ${{ steps.generate-changelog.outputs.changelog }} |
| 63 | + REPO_URL: ${{ env.SYNC_TARGET_REPOSITORY }} |
| 64 | + shell: bash |
| 65 | + |
| 66 | + - name: Create PR |
| 67 | + id: create-pr |
| 68 | + uses: peter-evans/create-pull-request@v6 |
| 69 | + with: |
| 70 | + token: ${{ steps.generate-token.outputs.token }} |
| 71 | + base: ${{ env.BASE_BRANCH }} |
| 72 | + branch: sync-tier4-upstream-${{ inputs.sync-target-tag }} |
| 73 | + title: "chore: sync upstream up to ${{ inputs.sync-target-tag }}" |
| 74 | + body: ${{ steps.replace-pr-number-to-url.outputs.changelog }} |
| 75 | + labels: | |
| 76 | + bot |
| 77 | + sync-tier4-upstream |
| 78 | + author: github-actions <[email protected]> |
| 79 | + signoff: true |
| 80 | + delete-branch: true |
| 81 | + |
| 82 | + - name: Check outputs |
| 83 | + run: | |
| 84 | + echo "Pull Request Number - ${{ steps.create-pr.outputs.pull-request-number }}" |
| 85 | + echo "Pull Request URL - ${{ steps.create-pr.outputs.pull-request-url }}" |
| 86 | +
|
| 87 | + - name: Enable auto-merge |
| 88 | + if: ${{ steps.create-pr.outputs.pull-request-operation == 'created' }} |
| 89 | + run: gh pr merge --merge --auto "${{ steps.create-pr.outputs.pull-request-number }}" |
| 90 | + shell: bash |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} |
0 commit comments