Skip to content

Conversation

@sqs
Copy link
Member

@sqs sqs commented Jan 14, 2020

Usage:

Run:

go install ./cmd/src && \
docker build -t sqs1/add-lsif-to-build-pipeline-action actions/add-lsif-to-build-pipeline && \
src actions exec -j 4 -keep-logs -f actions/add-lsif-to-build-pipeline/action.json  | \
  src campaign plan create-from-patches

image

This will create a campaign that adds GitHub Action LSIF build steps to repositories matched in the action.json file (see and change the query to match repositories that exist on your instance). Note: You should only use this with the test sd9 and sd9org repositories, because if you click the link and press Create, it will create PRs on real live repositories!

image

Ping me (@sqs) for help on anything here if you pick up this PR.

TODOs:

  • Format of action.json files and overall model for specifying what to run, which repositories to run it on, etc.
  • CLI UX (it's weird you need to pipe stuff)
  • Clean up code and add tests
  • Currently only works on Linux, needs to support macOS (the diff CLI flags we use only work on GNU diff not BSD diff, and the Docker volume mounting breaks due to macOS's /var/tmp/folders/... sandboxing)
  • Document (documentation & guide here: https://github.com/sourcegraph/sourcegraph/pull/8064 and also in the -help output of the commands)
  • The terminal library (that lets us print progress bars) does not properly handle colored text. If your terminal is too narrow, the progress bars "climb" up the screen. This is due to the terminal library thinking that a line has (for example) 80 chars but it only has (for example) 65 visible chars plus 15 ANSI escape sequence chars for colors. This appears to be a problem in all Go terminal libs. I started to make my own to fix this on a flight w/o WiFi; if it would be helpful, remind me to push it up.
  • The proposed src campaigns create command is not implemented
  • Remove sample actions in the actions/ dir. These are good candidates for examples in the docs, but they don't belong in this repo.

@mrnugget
Copy link
Contributor

I'm picking this up in 3.13

Copy link
Contributor

@mrnugget mrnugget left a comment

Choose a reason for hiding this comment

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

Leaving a first batch of notes to myself while reviewing/working on this PR.

}
displayUserCacheDir := strings.Replace(userCacheDir, os.Getenv("HOME"), "$HOME", 1)
var (
fileFlag = flagSet.String("f", "<stdin>", `The action file. (required)`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to myself: I think it might be more idiomatic to make -f optional and read from stdin if it's not set. Or use -f - to say "read from stdin"

Copy link
Contributor

@mrnugget mrnugget left a comment

Choose a reason for hiding this comment

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

Left more notes to myself


// Add to cache if successful.
if err == nil {
if err := x.opt.cache.set(ctx, cacheKey, status.Patch); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to myself: does this also write to the cache when status.Patch == CampaignPlanPatch{}? Or do we need the len(patch) > 0 check here too?

mrnugget added a commit that referenced this pull request Jan 22, 2020
I think this makes a lot more sense from a users perspective, especially
with the upcoming changes in #80.
mrnugget added a commit that referenced this pull request Jan 23, 2020
I think this makes a lot more sense from a users perspective, especially
with the upcoming changes in #80.
@mrnugget
Copy link
Contributor

Note: I think the problem is not BSD diff vs GNU diff but rather GNU diff 2.8.1 vs GNU diff 3.7.

@mrnugget
Copy link
Contributor

Update: I think I'm happy with the code so far and would move on to giving a last shot at fixing the moving/scrolling UI, documentation and adding campaign create.

The corresponding Sourcegraph GraphQL API mutations will be (temporarily) removed until they support full remote execution of arbitrary tools.
@mrnugget
Copy link
Contributor

I broke the UI logic, I think, since it now also prints progress when the output is piped to another command.

@mrnugget
Copy link
Contributor

@sqs I can't think of any UX improvements that are hard requirements right now. I actually do like the piping. What were your concerns there?

I started to work on campaigns create in this PR here #87 which is stacked on top of this one.

@mrnugget
Copy link
Contributor

@mrnugget mrnugget marked this pull request as ready for review January 27, 2020 13:36
@mrnugget mrnugget changed the title WIP: add src actions exec command to generate arbitrary campaign diffs Add src actions exec command to generate arbitrary campaign diffs Jan 27, 2020
@mrnugget
Copy link
Contributor

I'm going to merge this now because the basic feature set and documentation is there. It works, but can be polished:

  • "interactive" mode for creating campaigns that opens the editor
  • fix the "scrolling" up of the progress bar
  • show progress when CLI is downloading repository archives
  • ...

But the PR has gotten quite big and further additions would make it unwieldy. Once it's merged I'll open new PRs to polish things.

@sqs Let me know if you have any specific concerns besides the ones I mentioned, or whether your don't think the things I've mentioned don't have priority right now.

@mrnugget mrnugget merged commit cbb5f08 into master Jan 27, 2020
scjohns pushed a commit that referenced this pull request Apr 24, 2023
I think this makes a lot more sense from a users perspective, especially
with the upcoming changes in #80.
scjohns pushed a commit that referenced this pull request Apr 24, 2023
)

* WIP: add `src actions exec` command to generate arbitrary campaign diffs

* Use `/tmp` as TempDir prefix because it works with Docker for Mac

* Remove fixed TODO comment

* Fall back to degraded behavior for GNU diff <3.3

* Remove example actions

* Check all diff flags that we need

* Various small fixes and cleanups

* Check whether stdin is a pipe before attempting to read

* Extract getDockerImageContentDigest

* Extract Actions UI printer into separate struct

* Log if skipping repo because of missing default branch

* Stop leaking goroutine

* Move preparation of action to separate function

* Flush at the end of update not at the beginning

* Add timeout flag for action execution

* We don't need a trailing slash

* Consistently use temp dir prefix

* Rename types to get rid of redundant information

* Use "-" to signify STDIN

* Remove campaign plan creation via spec

The corresponding Sourcegraph GraphQL API mutations will be (temporarily) removed until they support full remote execution of arbitrary tools.

* Revert extraction of UI printer to fix piping

* Add `campaigns create` command

* Add documentation examples for `src actions exec`

* Print friendly message when a campaign has been created

* More documentation

* Use full or relative URL of Campaign

* Use ResolveReference to construct Campaign URL

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
@keegancsmith keegancsmith deleted the a8n/actions branch November 11, 2025 20:52
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.

3 participants