Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
with:
fetch-depth: 0
# Fetch complete history depth only if the PR is not a chore.
fetch-depth: ${{ !contains(github.event.pull_request.labels.*.name, 'dependencies') && !contains(github.event.pull_request.labels.*.name, 'Skip Changelog') && !contains(github.event.pull_request.title, '[chore]') && '0' || '1' }}
Comment on lines +35 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough experience with this level of programming inside github actions, but I believe a good alternative to investigate could be to have a step using bash and the gh (Github CLI tool) to run the logic and put the result in an output, which could then be used here. Just an idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't know how to use gh to get the current pull request labels or title. Even if we did, we'd still only be able to test this outside a run of github actions.

You can see in this PR how I toggled labels on and off ; for each run, I was then able to read the execution of the changelog job, and see what fetch-depth value was set to. Hopefully, that covered all cases. I certainly got bit by my optimism before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we be able to test it only outside of a run? Not sure I understand.

To illustrate a bit better how it would look:

should_skip_bool="$(
  GH_PAGER= gh pr view "$PR_NUMBER" --repo "$REPO" \
    --json title,labels \
    --jq '(.title | ascii_downcase | contains("[chore]"))
          or ( [.labels[].name | ascii_downcase]
               | any(. == "skip changelog" or . == "dependencies") )'
)"

# Convert boolean to 1/0
value="0"
if [[ "$should_skip_bool" == "true" ]]; then
  value="1"
fi

echo "DEPTH=$value" >> $GITHUB_OUTPUT

The env vars would be set in the workflow step by using:

env:
  REPO: ${{ github.repository }}
  PR_NUMBER: ${{ github.event.pull_request.number }}
  # gh uses GH_TOKEN; Actions provides GITHUB_TOKEN automatically.
  GH_TOKEN: ${{ github.token }}

And later the output could be used in another step like:

  - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
    with:
      fetch-depth: ${{ steps.checkout_depth.outputs.depth }}

The shell script is testable locally:

$ GH_PAGER= gh pr view "42340" --repo open-telemetry/opentelemetry-collector-contrib --json title,labels \
    --jq '(.title | ascii_downcase | contains("[chore]"))
          or ( [.labels[].name | ascii_downcase]
               | any(. == "skip changelog" or . == "dependencies") )'
true

And the whole action could also be testable locally using act.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, you lost me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, no opinions held strongly here. 😂

Copy link
Member

@douglascamata douglascamata Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buuuut if you are interested in transforming this logic into a shell script that we can run locally and more easily test/debug, I can try to prepare a better explanation.

- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
with:
go-version: oldstable
Expand Down