This action return contexts (see Concepts) according to labels on opened pull requests.
The behavior of the action depends on the event that triggered the workflow:
- pull_request:
- unlabeled: See Unlabeled workflow
- else: See Pull request workflow
- push:
- branch=main or branch=master: See Push to main or master branch workflow
Explanation:
Context: A context is a JSON formated string that contains the following keys:
environment
: The environment designated by the labelservice
: The service designated by the label
This action return an array of contexts under the contexts
output.
Example:
From the following labels:
staging-api
staging-web
The output will be:
[
{
"environment": "staging",
"service": "api"
},
{
"environment": "staging",
"service": "web"
}
]
According to the event that triggered the workflow, the action will return contexts as follows.
Steps:
- Get the labels in the pull request which triggered the workflow
- Check if the labels are present in any other opened pull request
- If some of the labels are present in any other opened pull request, remove the labels from other pull requests
- Return the contexts associated with the labels
Example:
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- labeled
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Get contexts
uses: @BeOpinion/action-smart-ci-triggers@v3.2.0
id: get-contexts
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: |
echo "Contexts to deploy=${{ steps.get-contexts.outputs.contexts }}"
Steps:
- Get the label removed from the pull request which triggered the workflow
- Check if the label is present in any other opened pull request
- If the label is not present in any other opened pull request, return the context associated with the label
- If the label is present in another opened pull request, return an empty array
Example:
on:
pull_request:
types:
- unlabeled
jobs:
rollback:
runs-on: ubuntu-latest
name: Rollback
steps:
- name: Get contexts
uses: @BeOpinion/action-smart-ci-triggers@v3.2.0
id: get-contexts
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Rollback
run: |
echo "Contexts to rollback=${{ steps.get-contexts.outputs.contexts }}"
Steps:
- Get the labels in all opened pull requests
- Return the contexts associated with the labels
Example:
on:
push:
branches:
- main
- master
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Get contexts
uses: @BeOpinion/action-smart-ci-triggers@v3.2.0
id: get-contexts
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: |
echo "Contexts to do not deploy=${{ steps.get-contexts.outputs.contexts }}"