Skip to content

Conversation

@lantoli
Copy link
Member

@lantoli lantoli commented Jan 9, 2026

Description

Allow use of run-script-and-commit GitHub action from non-Go projects, for example Terraform module repos.

Also fetches tags in case they're needed by the script to execute.

Link to any related issue(s): CLOUDP-365072

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

Comment on lines 48 to 56
run: |
GO_MOD_PATH="${{ inputs.repo-path }}go.mod"
echo "go_mod_path=$GO_MOD_PATH" >> $GITHUB_OUTPUT
if [ -f "$GO_MOD_PATH" ]; then
echo "is_go_project=true" >> $GITHUB_OUTPUT
else
echo "is_go_project=false" >> $GITHUB_OUTPUT
fi
Copy link

@semgrep-code-mongodb semgrep-code-mongodb bot Jan 9, 2026

Choose a reason for hiding this comment

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

Using variable interpolation ${{...}} with github context data in a run: step could allow an attacker to inject their own code into the runner. This would allow them to steal secrets and code. github context data can have arbitrary user input and should be treated as untrusted. Instead, use an intermediate environment variable with env: to store the data and use the environment variable in the run: script. Be sure to use double-quotes the environment variable, like this: "$ENVVAR".

🚀 Fixed in commit 778f89c 🚀

Copy link
Member Author

Choose a reason for hiding this comment

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

/fp no security issue as this code is equivalent to the previous code and we control what paths we pass

Copy link
Collaborator

Choose a reason for hiding this comment

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

it may help to pass this as an env var or atleast validate via regex that repo-path can only be a path-like string

Copy link
Member Author

Choose a reason for hiding this comment

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

@maastha cc @manupedrozo @EspenAlbert at the end I've changed repo-path to go-mod-path as it's only used for that, changed here: 778f89c

and adapted CFN repo which is the only one using it: mongodb/mongodbatlas-cloudformation-resources#1526

@lantoli lantoli marked this pull request as ready for review January 9, 2026 13:38
@lantoli lantoli requested a review from a team as a code owner January 9, 2026 13:38
Copilot AI review requested due to automatic review settings January 9, 2026 13:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables the run-script-and-commit GitHub action to work with non-Go projects (such as Terraform modules) by making Go setup conditional based on the presence of a go.mod file.

  • Adds conditional logic to detect whether the repository is a Go project
  • Makes the Go setup step conditional based on project type detection
  • Adds fetch-tags parameter to checkout action

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c
with:
go-version-file: ${{ format('{0}go.mod', inputs.repo-path) }}
go-version-file: ${{ steps.check-go.outputs.go_mod_path }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
go-version-file: ${{ steps.check-go.outputs.go_mod_path }}
go-version-file: ${{ steps.check-go.outputs.go_mod_path }}

using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
Copy link
Collaborator

Choose a reason for hiding this comment

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

what repository is checked out here when this is called from a different repo?

Copy link
Member Author

Choose a reason for hiding this comment

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

callee repo, for example cluster module repo

Copy link
Collaborator

@EspenAlbert EspenAlbert left a comment

Choose a reason for hiding this comment

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

Ty!

@lantoli lantoli merged commit e9a80b8 into master Jan 9, 2026
47 of 48 checks passed
@lantoli lantoli deleted the CLOUDP-365072_script_commit branch January 9, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants