|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to you under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +name: add-dependabot-changelog |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + branches: |
| 23 | + - "dependabot/*" |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: write |
| 27 | + |
| 28 | +jobs: |
| 29 | + |
| 30 | + add-changelog-entry: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + |
| 33 | + steps: |
| 34 | + |
| 35 | + - name: Fetch metadata |
| 36 | + id: dependabot-metadata |
| 37 | + uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7 # 2.3.0 |
| 38 | + with: |
| 39 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Find dependency attributes |
| 42 | + if: ${{ steps.dependabot-metadata.outputs.dependency-names }} |
| 43 | + shell: bash |
| 44 | + env: |
| 45 | + DEPENDENCY_NAMES: ${{ steps.dependabot-metadata.outputs.dependency-names }} |
| 46 | + DEPENDENCY_VERSION: ${{ steps.dependabot-metadata.outputs.new-version }} |
| 47 | + run: | |
| 48 | + DEPENDENCY_NAME=$(echo "$DEPENDENCY_NAMES" | tr "," '\n' | head -n 1) |
| 49 | + cat >> $GITHUB_ENV << EOF |
| 50 | + DEPENDENCY_NAME=$DEPENDENCY_NAME |
| 51 | + DEPENDENCY_VERSION=$DEPENDENCY_VERSION |
| 52 | + EOF |
| 53 | +
|
| 54 | + - name: Checkout repository |
| 55 | + if: ${{ steps.dependabot-metadata.outputs.dependency-names }} |
| 56 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| 57 | + |
| 58 | + - name: Set up Java & GPG |
| 59 | + if: ${{ steps.dependabot-metadata.outputs.dependency-names }} |
| 60 | + uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # 4.7.1 |
| 61 | + with: |
| 62 | + distribution: zulu |
| 63 | + java-version: 17 |
| 64 | + cache: maven |
| 65 | + server-id: apache.releases.https |
| 66 | + server-username: NEXUS_USERNAME |
| 67 | + server-password: NEXUS_PASSWORD |
| 68 | + gpg-private-key: ${{ secrets.GPG_SECRET_KEY }} |
| 69 | + |
| 70 | + - name: Find the release version major |
| 71 | + if: ${{ steps.dependabot-metadata.outputs.dependency-names }} |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + RELEASE_VERSION_MAJOR=$(./mvnw \ |
| 75 | + --non-recursive --quiet --batch-mode \ |
| 76 | + -DforceStdout=true \ |
| 77 | + -Dexpression=parsedVersion.majorVersion \ |
| 78 | + build-helper:parse-version help:evaluate \ |
| 79 | + | tail -n 1) |
| 80 | + echo "RELEASE_VERSION_MAJOR=$RELEASE_VERSION_MAJOR" >> $GITHUB_ENV |
| 81 | +
|
| 82 | + - name: Create changelog entry |
| 83 | + if: ${{ steps.dependabot-metadata.outputs.dependency-names }} |
| 84 | + shell: bash |
| 85 | + env: |
| 86 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 87 | + PR_ID: ${{ github.event.pull_request.number }} |
| 88 | + run: | |
| 89 | + if [ -d "src/changelog" ]; then |
| 90 | + RELEASE_CHANGELOG_FILEPATH="src/changelog/.${RELEASE_VERSION_MAJOR}.x.x" |
| 91 | + SAFE_DEPENDENCY_NAME=$(echo "$DEPENDENCY_NAME" | tr "[:upper:]" "[:lower:]" | sed -r 's/[^a-z0-9]/_/g' | sed -r 's/_+/_/g') |
| 92 | + CHANGELOG_ENTRY_FILEPATH="$RELEASE_CHANGELOG_FILEPATH/update_${SAFE_DEPENDENCY_NAME}.xml" |
| 93 | + mkdir -p $(dirname "$CHANGELOG_ENTRY_FILEPATH") |
| 94 | + cat > "$CHANGELOG_ENTRY_FILEPATH" << EOF |
| 95 | + <?xml version="1.0" encoding="UTF-8"?> |
| 96 | + <entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 97 | + xmlns="https://logging.apache.org/xml/ns" |
| 98 | + xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" |
| 99 | + type="updated"> |
| 100 | + <issue id="$PR_ID" link="$PR_URL"/> |
| 101 | + <description format="asciidoc">Update \`$DEPENDENCY_NAME\` to version \`$DEPENDENCY_VERSION\`</description> |
| 102 | + </entry> |
| 103 | + EOF |
| 104 | + fi |
| 105 | +
|
| 106 | + - name: Add & commit changes |
| 107 | + if: ${{ steps.dependabot-metadata.outputs.dependency-names }} |
| 108 | + shell: bash |
| 109 | + env: |
| 110 | + PR_ID: ${{ github.event.pull_request.number }} |
| 111 | + PR_BRANCH: ${{ github.head_ref }} |
| 112 | + run: | |
| 113 | + git add src/changelog |
| 114 | + git config user.name "ASF Logging Services RM" |
| 115 | + git config user.email [email protected] |
| 116 | + git commit -S -a -m "Add changelog for #$PR_ID" |
| 117 | + # Push to the branch |
| 118 | + git push |
0 commit comments