Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User input in github actions (specify repo branch, etc)

I want to create a github action to create an integration test environment. We already have a dockerized script which can do this, however, the environment is made up of 2+ repositories. So, in order to make this effective during development, we'd need to specify the branches of the other repos.

For example, let's say I have a PR in repo: frontend, branch: my-feature-brach. It requires repo: backend, branch: their-feature-branch. I'd like to kick off a build from my PR where it uses the branch of that PR (in the frontend repo), and ask me which branch to use for the backend repo.

Is this possible?

like image 782
Jeremy Gillick Avatar asked Dec 20 '19 18:12

Jeremy Gillick


People also ask

Can GitHub Actions take user input?

You can now specify input types for manually triggered workflows allowing you to provide a better experience to users of your workflow. In addition to the default string type, we now support choice , boolean , and environment .

How do I set an environment variable in GitHub Actions?

To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.

Do GitHub Actions run on branches?

Github Actions only triggers on default branch.

How do I run jobs sequentially in GitHub Actions?

To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .


1 Answers

You can define manually executable workflows, with inputs.

on: 
  workflow_dispatch:
    inputs:
      environment:
        description: 'Define env name'     
        required: true
        default: 'prod'
      branch:
        description: 'Define branch name'     
        required: true
        default: 'master'

Than you can use these predefined parameters like:

jobs:
  printInputs:
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo "Env: ${{ github.event.inputs.environment }}" 
        echo "Branch: ${{ github.event.inputs.branch }}"

I think you can support your use case with that. More details here.

like image 146
hEngi Avatar answered Oct 02 '22 13:10

hEngi