Skip to content

Allow modifying bundle exec commands

Alex Kalderimis requested to merge ajk-left-hook-gck-integration into master

What does this MR do and why?

This MR provides a mechanism to modify bundle exec invocations, aimed to be used in lefthook commands, but also broadly applicable.

The motivating need for this is the fact that lefthook fails to run most commands when using the GCK, due to the way the bundle is managed.

The mechanism introduced here is not GCK specific, but to use this with GCK commands, see the reproduction steps below.

How to use this with GCK

  1. Add the following script to somewhere:

    # gck-do
    #!/bin/bash
    
    if [[ -f "$GCK/.gck" ]]; then
        source "$GCK/.gck"
    else
        echo "GCK environment not set. Cannot run commands in GCK"
        exit 1
    fi
    
    cmd="$@"
    
    echo "Running '$cmd' in gck"
    
    gck command COMMAND="$cmd"

    (nb: we should probably add this script to the GCK repository)

  2. Then in the current environment, set the GL_BUNDLE_EXEC environment variable:

    export GL_BUNDLE_EXEC=/path/to/scripts/gck-do
  3. Modify a file under app/graphql/**

  4. Run lefthook run pre-push

Example output:

❯ lefthook run pre-push
Lefthook v0.7.7
RUNNING HOOKS GROUP: pre-push

prettier (SKIP. NO FILES FOR INSPECTION)

markdownlint (SKIP. NO FILES FOR INSPECTION)

graphql_docs (SKIP. NO FILES FOR INSPECTION)

stylelint (SKIP. NO FILES FOR INSPECTION)

rubocop (SKIP. NO FILES FOR INSPECTION)

eslint (SKIP. NO FILES FOR INSPECTION)

docs-metadata (SKIP. NO FILES FOR INSPECTION)

vale (SKIP. NO FILES FOR INSPECTION)

  EXECUTE > haml-lint
make: Entering directory '/home/alex/projects/gitlab/gck'
WARNING: The METRICS_TOKEN variable is not set. Defaulting to a blank string.
gck_redis-alt_1 is up-to-date
gck_webpack_1 is up-to-date
gck_postgres_1 is up-to-date
gck_redis_1 is up-to-date
gck_minio_1 is up-to-date
gck_gitaly_1 is up-to-date
gck_spring_1 is up-to-date
WARNING: The METRICS_TOKEN variable is not set. Defaulting to a blank string.
Running in `export WEBDRIVER_HEADLESS=true` mode: as the `$DISPLAY` is missing.
warning: parser/current is loading parser/ruby27, which recognizes2.7.5-compliant syntax, but you are running 2.7.4.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.

1 file inspected, 0 lints detected
make: Leaving directory '/home/alex/projects/gitlab/gck'



gettext (SKIP BY SETTINGS)

  EXECUTE > danger
make: Entering directory '/home/alex/projects/gitlab/gck'
WARNING: The METRICS_TOKEN variable is not set. Defaulting to a blank string.
gck_minio_1 is up-to-date
gck_webpack_1 is up-to-date
gck_redis-alt_1 is up-to-date
gck_postgres_1 is up-to-date
gck_redis_1 is up-to-date
gck_gitaly_1 is up-to-date
gck_spring_1 is up-to-date
WARNING: The METRICS_TOKEN variable is not set. Defaulting to a blank string.
Running in `export WEBDRIVER_HEADLESS=true` mode: as the `$DISPLAY` is missing.
Results:

Warnings:
- [ ] 9fb118b8103313abfb3ead247514ba0ab1370540: The commit subject must contain at least 3 words. For more information, take a look at our [Commit message guidelines](https://docs.gitlab.com/ee/development/contributing/merge_request_workflow.html#commit-messages-guidelines).
- [ ] 9fb118b8103313abfb3ead247514ba0ab1370540: The commit subject must start with a capital letter. For more information, take a look at our [Commit message guidelines](https://docs.gitlab.com/ee/development/contributing/merge_request_workflow.html#commit-messages-guidelines).

Messages:
- [ ] **[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html)**:

If this merge request [doesn't need a CHANGELOG entry](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry), feel free to ignore this message.
make: Leaving directory '/home/alex/projects/gitlab/gck'



SUMMARY: (done in 7.92 seconds)
✔️  haml-lint
✔️  danger

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Alex Kalderimis

Merge request reports

Loading