Skip to content

Commit

Permalink
chore(ci): simplify chanelog validation to always check for authors (#…
Browse files Browse the repository at this point in the history
…21463)

* dummy changelog

* remove redundant authors argument
  • Loading branch information
pront authored Oct 9, 2024
1 parent aeaeecd commit e250dcb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 44 deletions.
35 changes: 7 additions & 28 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,32 @@ jobs:
env:
PR_HAS_LABEL: ${{ contains( github.event.pull_request.labels.*.name, 'no-changelog') }}
steps:
# checkout full depth because in the check_changelog_fragments script, we need to specify a
# merge base. If we only shallow clone the repo, git may not have enough history to determine
# the base.
# Checkout full depth because in the check_changelog_fragments script, we need to specify a
# merge base. If we only shallow clone the repo, git may not have enough history to determine
# the base.
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Generate authentication token
# don't run this step if the PR is from a fork or dependabot since the secrets won't exist
# Don't run this step if the PR is from a fork or dependabot since the secrets won't exist
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
id: generate_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
with:
app_id: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_ID }}
private_key: ${{ secrets.GH_APP_DATADOG_VECTOR_CI_APP_PRIVATE_KEY }}

- name: Get PR comment author
# don't run this step if the PR is from a fork or dependabot since the secrets won't exist
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
id: author
uses: tspascoal/get-user-teams-membership@v3
with:
username: ${{ github.actor }}
team: 'Vector'
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}

- env:
# if the prior step did not run, this var will be ''
AUTHOR_IS_TEAM_MEMBER: ${{ steps.author.outputs.isTeamMember }}
run: |
- run: |
if [[ $PR_HAS_LABEL == 'true' ]] ; then
echo "'no-changelog' label detected."
exit 0
fi
# helper script needs to reference the master branch to compare against
# Helper script needs to reference the master branch to compare against
git fetch origin master:refs/remotes/origin/master
# If the PR author is an external contributor, validate that the
# changelog fragments added contain the author line for website rendering.
args=""
if [[ $AUTHOR_IS_TEAM_MEMBER != 'true' ]] ; then
echo "PR author detected to be an external contributor."
args="--authors"
fi
./scripts/check_changelog_fragments.sh ${args}
./scripts/check_changelog_fragments.sh
check-changelog:
name: Changelog
Expand Down
27 changes: 11 additions & 16 deletions scripts/check_changelog_fragments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,17 @@ while IFS= read -r fname; do
exit 1
fi

# if specified, this option validates that the contents of the news fragment
# contains a properly formatted authors line at the end of the file, generally
# used for external contributor PRs.
if [[ $1 == "--authors" ]]; then
last=$( tail -n 1 "${CHANGELOG_DIR}/${fname}" )
if [[ "${last}" == "authors: "*@* ]]; then
echo "invalid fragment contents: author should not be prefixed with @"
exit 1
elif [[ "${last}" == "authors: "*,* ]]; then
echo "invalid fragment contents: authors should be space delimited, not comma delimited."
exit 1
elif ! [[ "${last}" =~ ^(authors: .*)$ ]]; then
echo "invalid fragment contents: author option was specified but fragment ${fname} contains no authors."
exit 1
fi

# Each fragment should have a properly formatted authors line at the end of the file.
last=$( tail -n 1 "${CHANGELOG_DIR}/${fname}" )
if [[ "${last}" == "authors: "*@* ]]; then
echo "invalid fragment contents: author should not be prefixed with @"
exit 1
elif [[ "${last}" == "authors: "*,* ]]; then
echo "invalid fragment contents: authors should be space delimited, not comma delimited."
exit 1
elif ! [[ "${last}" =~ ^(authors: .*)$ ]]; then
echo "invalid fragment contents: author option was specified but fragment ${fname} contains no authors."
exit 1
fi

done <<< "$FRAGMENTS"
Expand Down

0 comments on commit e250dcb

Please sign in to comment.