Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
git-pull-request

GitHub Action

Select target action

v0.3.3

Select target action

git-pull-request

Select target action

Configure the matrix job directory in GitHub Label

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Select target action

uses: ponkio-o/[email protected]

Learn more about this action in ponkio-o/select-target-action

Choose a version

select-target-action

Configure the matrix job directory in GitHub Label.

Setup

1. Create configuration file

Create a json file in the following format. Specify the label name as key and target directory as value.
The config file name or directory can be specified, but .deploy_target.json is used by default.

{
    "target:develop": [
        "envs/development"
    ],
    "target:staging": [
        "envs/staging"
    ],
    "target:production": [
        "envs/production"
    ],
    "target:all" : [
        "envs/development",
        "envs/staging",
        "envs/production"
    ]
}

2. Create GitHub Labels

CUI

If the jq and gh commands are installed, the following commands are useful.

export REPO=ponkio-o/select-target-action
export COLOR=5319E7
cat .deploy_target.json | jq -r 'keys | .[]' | xargs -I @ gh label create @ --color $COLOR --repo $REPO

ref. https://cli.github.com/manual/gh_label_create

Example

$ cat .deploy_target.json | jq -r 'keys | .[]' | xargs -I @ gh label create @ --color $COLOR --repo $REPO
✓ Label "target:all" created in ponkio-o/select-target-action
✓ Label "target:develop" created in ponkio-o/select-target-action
✓ Label "target:production" created in ponkio-o/select-target-action
✓ Label "target:staging" created in ponkio-o/select-target-action

GUI

Please refer to following doc.
https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels#creating-a-label

3. Setup Workflow

GitHub Actions are configured as follows:

name: Terraform PR check

on:
  pull_request:
    types: [opened]
    branches:
      - main

jobs:
  set-matrix:
    name: Set matrix job
    runs-on: ubuntu-latest

    outputs:
      workdir: ${{ steps.set_matrix.outputs.matrix-workdir }}

    steps:
      - name: checkout
        uses: actions/checkout@v3

      - name: Set matrix
        id: set_matrix
        uses: ponkio-o/select-target-action@main

  plan:
    needs: [set-matrix]
    name: Plan
    runs-on: ubuntu-latest

    strategy:
      matrix:
        workdir: ${{fromJson(needs.set-matrix.outputs.workdir)}}

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup terraform
        uses: hashicorp/setup-terraform@v1

      - name: Terraform plan
        working-directory: ${{ matrix.workdir }}
        run: terraform plan -input=false -no-color
...

Usage

The directories set in the key of the given label are merged and returned as an array.

Deployment

Assign labels to the Pull Request. You can also select multiple labels.

Example: target:all

image

Example: target:develop & target:staging

image

Example: target:all & target:staging

image

Inputs

All inputs are optional.

Name Description Default
config_file Path to configuration file .deploy_target.json
token GITHUB_TOKEN or PersonalAccessToken(PAT) GITHUB_TOKEN

Outputs

The working directory outputs as an array.

["envs/dev","envs/stg","envs/prod"]