Skip to content

Add docs on how to run from Github Actions CI/CD Workflow #1540

Description

@aaronsteers

Describe the feature or problem you’d like to solve

I'd like to be able to run gh cli from within a github action. The only install action I see is to manually download on the linux-based github runner (container) is to curl a hard-coded url, which will be immediately stale and will need it's version updated periodically. Is this the best way? Is it already installed on github runners? Some documentation here would be extremely helpful. Thanks!

Proposed solution

Documentation on the recommended way to run within github actions would be much appreciated.

Additional context

I've searched google and the available repo docs and github docs to no avail.

Activity

  1. aaronsteers commented on Aug 15, 2020

    @aaronsteers
    Author

    Update: Installing works with the below but it fails to authenticate, prompting for a GUI-based URL MFA.

          - name: Install GitHub CLI
            run: |
              URL=https://github.com/cli/cli/releases/download/v0.11.1/gh_0.11.1_linux_amd64.deb
              TEMP_DIR="$(pwd)"
              TEMP_DEB="$(pwd)/gh_0.11.1_linux_amd64.deb"
              wget -O "$TEMP_DEB" "$URL"
              ls -la $TEMP_DIR
              sudo apt install "$TEMP_DEB"
              rm -f "$TEMP_DEB"
    

    Failure log:

    Run echo "Checking out from PR URL: https://api.github.com/repos/slalom-ggp/dataops-infra/pulls/122"
    Checking out from PR URL: https://api.github.com/repos/slalom-ggp/dataops-infra/pulls/122
    Notice: authentication required
    Press Enter to open github.com in your browser... /usr/bin/xdg-open: 851: /usr/bin/xdg-open: www-browser: not found
    /usr/bin/xdg-open: 851: /usr/bin/xdg-open: links2: not found
    /usr/bin/xdg-open: 851: /usr/bin/xdg-open: elinks: not found
    /usr/bin/xdg-open: 851: /usr/bin/xdg-open: links: not found
    /usr/bin/xdg-open: 851: /usr/bin/xdg-open: lynx: not found
    /usr/bin/xdg-open: 851: /usr/bin/xdg-open: w3m: not found
    xdg-open: no method available for opening 'https://github.com/login/oauth/authorize?client_id=178c6fc778ccc68e1d6a&redirect_uri=http%3A%2F%2F127.0.0.1%3A33511%2Fcallback&scope=repo+read%3Aorg+gist&state=2f9d7df6cfbb09aefbf7'
    error opening web browser: exit status 3
    Please open the following URL manually:
    https://github.com/login/oauth/authorize?client_id=178c6fc778ccc68e1d6a&redirect_uri=http%3A%2F%2F127.0.0.1%3A33511%2Fcallback&scope=repo+read%3Aorg+gist&state=2f9d7df6cfbb09aefbf7
    If you are on a server or other headless system, use this workaround instead:
      1. Complete authentication on a GUI system;
      2. Copy the contents of `~/.config/gh/hosts.yml` to this system.
    
  2. aaronsteers commented on Aug 15, 2020

    @aaronsteers
    Author

    Any plans to do something like https://github.com/marketplace/actions/setup-hub?

  3. mislav commented on Aug 17, 2020

    @mislav
    Contributor

    @aaronsteers GitHub CLI is pre-installed in Actions runners. To use it:

    - uses: actions/checkout@v2
    
    - name: GitHub CLI example
      run: gh issue list
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

    I understand that this has to be better documented; I'll add a label as a TODO item for us. Thanks for your ask!

  4. aaronsteers commented on Aug 17, 2020

    @aaronsteers
    Author

    @mislav - Awesome. That's a big help.

  5. trim21 commented on Sep 17, 2020

    @trim21

    When version 1.0.0 could be included in github actions? I'm looking forward to use new feature of gh.

  6. mislav commented on Sep 17, 2020

    @mislav
    Contributor

    @trim21 It usually doesn't take too long! In the meantime you can always download the binary directly from releases via a script.

  7. tapsboy commented on Sep 18, 2020

    @tapsboy

    Came here to look for the same and the update on 1.0.0 release, especially to utilize gh release. Instead, I ended up learning how nekos/act isn't exactly same as hosted github runners and what self-hosted runners are :) Glad I did.

    FWIW, I found this for anyone looking: https://github.com/actions/virtual-environments#updates-to-virtual-environments . It's a weekly cadence, so hopefully 1.0.0 will be in ubuntu-latest soon

  8. happiness801 commented on Sep 22, 2020

    @happiness801

    Great to hear that gh will be available by default to Actions cloud runners, however, what would be the best way to make gh CLI available on self-hosted runners? I think this is the use case for something like actions/setup-cli.

  9. mislav commented on Sep 23, 2020

    @mislav
    Contributor

    @happiness801 Something like:

    # Linux
    wget -O- https://github.com/cli/cli/releases/download/v1.0.0/gh_1.0.0_linux_amd64.tar.gz | tar -xz --strip-components 1 --wildcards -- \*/bin/gh
    
    # macOS
    curl -fsSL https://github.com/cli/cli/releases/download/v1.0.0/gh_1.0.0_macOS_amd64.tar.gz | tar -xz --strip-components 1 -- \*/bin/gh

    You will then be able to invoke bin/gh in the current directory.

  10. added
    coreThis issue is not accepting PRs from outside contributors
    on Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreThis issue is not accepting PRs from outside contributorsdocsenhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions