-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add process-dependabot-reusable workflow (Bash-based alternative)
#419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ppkarwasz
wants to merge
28
commits into
main
Choose a base branch
from
feat/dependabot-add-changelog2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
57f5ae9
feat: add `process-dependabot-reusable` workflow (Bash-based alternatβ¦
ppkarwasz 305af05
fix: Typos detected by Copilot
ppkarwasz 32fe361
fix: install `xmlstarlet`
ppkarwasz 59ea4d2
fix: replace `apt` with `apt-get`
ppkarwasz 27bd899
feat: Split Dependabot workflow into privileged and unprivileged parts
ppkarwasz 6f9d490
fix: limit the number of tokens
ppkarwasz a1f91ab
fix: drop all permissions by default
ppkarwasz ef0d793
Apply suggestions from code review
ppkarwasz da481c2
fix: switch to `dependabot/fetch-metadata`
ppkarwasz fbdf609
fix: apply review suggestions
ppkarwasz d2b0c59
fix: extract PR data from caller of `process-dependabot-reusable`
ppkarwasz 9565410
fix: inline user-name and user-email
ppkarwasz f88dade
fix: add `changelog-path` and remove `xmlstarlet`
ppkarwasz 3c86f2d
fix: sort inputs
ppkarwasz 4fd4cf0
fix: filters on PR user
ppkarwasz f78eab8
fix: remove computable parameters
ppkarwasz a78b727
fix: refactor XML escaping
ppkarwasz 615116f
fix: debug `workflow_run` payload
ppkarwasz 499214f
fix: remove license line
ppkarwasz 72e0f9c
fix: add comments to checks
ppkarwasz 2525d34
fix: check order
ppkarwasz 9a008db
Merge branch 'main' into feat/dependabot-add-changelog2
ppkarwasz 928fe46
fix: adapt to `ppkarwasz` organisation
ppkarwasz 2d9b235
Bump Dependabot workflow dependencies
dependabot[bot] c5d1ed3
Update Dependabot workflows dependencies
ppkarwasz 310d069
Remove commit signing
ppkarwasz f6ef80d
Modify preconditions
ppkarwasz 725cdbd
Merge branch 'feat/dependabot-add-changelog-test' into feat/dependaboβ¦
ppkarwasz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| name: Dependabot Analyze PR | ||
|
|
||
| on: | ||
| workflow_call: { } | ||
|
|
||
| # Explicitly drop all permissions inherited from the caller for security. | ||
| # Reference: https://docs.github.com/en/actions/sharing-automations/reusing-workflows#access-and-permissions | ||
| permissions: { } | ||
|
|
||
| jobs: | ||
|
|
||
| analyze-pull-request: | ||
| # Defense-in-depth (in case the caller forgets): | ||
| # `github.actor` prevents recursive calls when `github-actions[bot]` pushes to the PR; | ||
| # `github.event.pull_request.user.login` skips PRs not opened by Dependabot. | ||
| if: ${{ | ||
| github.actor == 'dependabot[bot]' | ||
| && github.event.pull_request.user.login == 'dependabot[bot]' | ||
| }} | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
|
|
||
| - name: Fetch Dependabot metadata | ||
| id: dependabot | ||
| uses: dependabot/fetch-metadata@ffa630c65fa7e0ecfa0625b5ceda64399aea1b36 # 3.0.0 | ||
| with: | ||
| github-token: ${{ github.token }} | ||
|
|
||
| # Creates the data required by the `process-dependabot-reusable` workflow as a JSON file. | ||
| - name: Create artifact | ||
| shell: bash | ||
| env: | ||
| UPDATED_DEPENDENCIES: ${{ steps.dependabot.outputs.updated-dependencies-json }} | ||
| run: | | ||
| echo "$UPDATED_DEPENDENCIES" > updated_dependencies.json | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # 7.0.1 | ||
| with: | ||
| name: dependabot-metadata | ||
| path: updated_dependencies.json |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| name: Dependabot Process PR | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| changelog-path: | ||
| description: The path to the changelog directory (e.g. `src/changelog/.2.x.x`) | ||
| required: true | ||
| type: string | ||
| secrets: | ||
| RECURSIVE_TOKEN: | ||
| description: "A PAT with `contents: write` permission to push changes and trigger the next workflow run" | ||
| required: true | ||
|
|
||
| # Explicitly drop all permissions inherited from the caller for security. | ||
| # Reference: https://docs.github.com/en/actions/sharing-automations/reusing-workflows#access-and-permissions | ||
| permissions: { } | ||
|
|
||
| jobs: | ||
|
|
||
| generate-changelog: | ||
| # Defense-in-depth (in case the caller forgets): | ||
| # `github.actor` prevents recursive calls when `github-actions[bot]` pushes to the PR; | ||
| # `github.event.workflow_run.conclusion` only runs after a successful analysis workflow. | ||
| if: ${{ | ||
| github.actor == 'dependabot[bot]' | ||
| && github.event.workflow_run.conclusion == 'success' | ||
| }} | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| # The default GITHUB_TOKEN will be used to enable the "auto-merge" on the PR | ||
| # This requires the following two permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
|
|
||
| - name: Get pull request metadata | ||
| id: pr | ||
| env: | ||
| # Reference of the payload: https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_run | ||
| # | ||
| # The structure of `pull_requests` is not documented, so we'll dump it for debugging purposes. | ||
| PULL_REQUESTS: ${{ toJSON(github.event.workflow_run.pull_requests) }} | ||
| run: | | ||
| # Print payload for debugging | ||
| jq <<< "$PULL_REQUESTS" | ||
| echo "id=$(echo "$PULL_REQUESTS" | jq -r '.[0].number')" >> "$GITHUB_OUTPUT" | ||
| echo "head-ref=$(echo "$PULL_REQUESTS" | jq -r '.[0].head.ref')" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Fetch Dependabot metadata | ||
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # 8.0.1 | ||
| with: | ||
| github-token: ${{ github.token }} | ||
| name: dependabot-metadata | ||
| path: ${{ runner.temp }} | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
|
|
||
| - name: Check out repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 6.0.2 | ||
| with: | ||
| ref: ${{ steps.pr.outputs.head-ref }} | ||
| token: ${{ secrets.RECURSIVE_TOKEN }} | ||
|
|
||
| - name: Create changelog entries | ||
| shell: bash | ||
| env: | ||
| PR_ID: ${{ steps.pr.outputs.id }} | ||
| PR_URL: ${{ github.server_url }}/${{ github.repository }}/pull/${{ steps.pr.outputs.id }} | ||
| CHANGELOG_PATH: ${{ inputs.changelog-path }} | ||
| UPDATED_DEPENDENCIES: ${{ runner.temp }}/updated_dependencies.json | ||
| run: | | ||
| # Escapes special XML characters in a string | ||
| xml_escape() { sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g'; } | ||
|
|
||
| # Generates the content of a changelog entry | ||
| function generate_changelog_entry() { | ||
| local dependency="$1" | ||
| local issue_id=$(xml_escape <<< "$PR_ID") | ||
| local issue_link=$(xml_escape <<< "$PR_URL") | ||
| local dependency_name=$(echo "$dependency" | jq -r '.dependencyName' | xml_escape) | ||
| local new_version=$(echo "$dependency" | jq -r '.newVersion' | xml_escape) | ||
| cat << CHANGELOG_ENTRY | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xmlns="https://logging.apache.org/xml/ns" | ||
| xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" | ||
| type="updated"> | ||
| <issue id="$issue_id" link="$issue_link"/> | ||
| <description format="asciidoc">Update \`$dependency_name\` to version \`$new_version\`</description> | ||
| </entry> | ||
| CHANGELOG_ENTRY | ||
| } | ||
|
|
||
| # Ensure the changelog directory exists | ||
| mkdir -p "$CHANGELOG_PATH" | ||
| cd "$CHANGELOG_PATH" | ||
|
|
||
| # Generate the changelog entries for each updated dependency | ||
| cat "$UPDATED_DEPENDENCIES" | jq --compact-output '.[]' | while read -r dependency; do | ||
| # Extract the dependency name and version | ||
| dependency_name=$(echo "$dependency" | jq -r '.dependencyName') | ||
| changelog_file_name=$(echo "update_${dependency_name,,}.xml" | sed -r -e 's/[^a-z0-9.-]/_/g' -e 's/_+/_/g') | ||
| generate_changelog_entry "$dependency" > "$changelog_file_name" | ||
| done | ||
|
|
||
| - name: Add & commit changes | ||
| shell: bash | ||
| env: | ||
| CHANGELOG_PATH: ${{ inputs.changelog-path }} | ||
| PR_ID: ${{ steps.pr.outputs.id }} | ||
| run: | | ||
| git add "$CHANGELOG_PATH" | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git commit -m "Generate changelog entries for #$PR_ID" | ||
| git push origin | ||
|
|
||
| - name: Enable auto-merge on PR | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR_ID: ${{ steps.pr.outputs.id }} | ||
| run: | | ||
| gh pr merge --squash --auto "$PR_ID" | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xmlns="https://logging.apache.org/xml/ns" | ||
| xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" | ||
| type="added"> | ||
| <issue id="417" link="https://github.com/apache/logging-parent/issues/417"/> | ||
| <description format="asciidoc"> | ||
| Added `process-dependabot-reusable` to handle Dependabot PRs under RTC restrictions. | ||
| </description> | ||
| </entry> |
This file contains hidden or 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
50 changes: 50 additions & 0 deletions
50
src/site/antora/modules/ROOT/examples/process-dependabot.yaml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| name: "Dependabot Process PR" | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: | ||
| - "Dependabot Analyze PR" | ||
| types: | ||
| - completed | ||
|
|
||
| permissions: { } | ||
|
|
||
| jobs: | ||
|
|
||
| # tag::process-dependabot[] | ||
| process-dependabot: | ||
| # Skip this workflow on commits not pushed by Dependabot | ||
| if: ${{ | ||
| github.repository == 'apache/logging-parent' | ||
| && github.actor == 'dependabot[bot]' | ||
| && github.event.workflow_run.conclusion == 'success' | ||
| }} | ||
| uses: apache/logging-parent/.github/workflows/process-dependabot-reusable.yaml@rel/{project-version} | ||
| permissions: | ||
| # The default GITHUB_TOKEN will be used to enable the "auto-merge" on the PR | ||
| # This requires the following two permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| secrets: | ||
| RECURSIVE_TOKEN: ${{ secrets.DEPENDABOT_TOKEN }} | ||
| with: | ||
| # The path to the changelog directory for the current development branch. | ||
| changelog-path: src/changelog/.2.x.x | ||
| # end::process-dependabot[] |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.