Skip to content

Commit de9599d

Browse files
committed
Added README
1 parent 5ad7e0c commit de9599d

File tree

1 file changed

+117
-13
lines changed

1 file changed

+117
-13
lines changed

README.yaml

Lines changed: 117 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
# Name of this project
8-
name: example-github-action-composite
8+
name: github-action-yaml-config-query
99

1010
# Tags of this project
1111
tags:
@@ -18,25 +18,28 @@ tags:
1818
license: "APACHE2"
1919

2020
# Canonical GitHub repo
21-
github_repo: cloudposse/example-github-action-composite
21+
github_repo: cloudposse/github-action-yaml-config-query
2222

2323
# Badges to display
2424
badges:
2525
- name: "Latest Release"
26-
image: "https://img.shields.io/github/release/cloudposse/example-github-action-composite.svg"
27-
url: "https://github.com/cloudposse/example-github-action-composite/releases/latest"
26+
image: "https://img.shields.io/github/release/cloudposse/github-action-yaml-config-query.svg"
27+
url: "https://github.com/cloudposse/github-action-yaml-config-query/releases/latest"
2828
- name: "Slack Community"
2929
image: "https://slack.cloudposse.com/badge.svg"
3030
url: "https://slack.cloudposse.com"
3131

3232
related: []
3333

3434
# Short description of this project
35-
description: Template repository of composite GitHub Action
35+
description: Define YAML document, filter it with JSON query and get result as JSON string
3636

3737
introduction: |-
38-
This is template repository to create composite GitHub Actions.
39-
Feel free to use it as reference and starting point.
38+
Utility action allow to declare YAML structured document as an input and get it's part as the action outputs
39+
referenced using JQ.
40+
41+
This action is useful in simplifing complext GitHub action workflows in different ways.
42+
For examples follow [usage](#usage) section.
4043
4144
references:
4245
- name: "github-actions-workflows"
@@ -48,6 +51,7 @@ references:
4851

4952
# How to use this project
5053
usage: |-
54+
### Define constants
5155
```yaml
5256
name: Pull Request
5357
on:
@@ -56,17 +60,117 @@ usage: |-
5660
types: [opened, synchronize, reopened, closed, labeled, unlabeled]
5761
5862
jobs:
59-
context:
63+
demo:
6064
runs-on: ubuntu-latest
6165
steps:
62-
- name: Example action
63-
uses: cloudposse/example-github-action-composite@main
64-
id: example
66+
- name: Context
67+
id: context
68+
uses: cloudposse/github-action-yaml-config-query@main
6569
with:
66-
param1: true
70+
config: |
71+
image: acme/example
72+
tag: sha-${{ github.sha }}
6773
74+
- run: |
75+
docker run ${{ steps.context.outputs.image }}:${{ steps.context.outputs.tag }}
76+
```
77+
78+
### Implement if/else
79+
```yaml
80+
name: Promote
81+
on:
82+
workflow_call:
83+
inputs:
84+
from:
85+
required: false
86+
type: string
87+
88+
jobs:
89+
demo:
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Context
93+
id: from
94+
uses: cloudposse/github-action-yaml-config-query@main
95+
with:
96+
query: .${{ inputs.from == '' }}
97+
config: |-
98+
true:
99+
tag: ${{ github.sha }}
100+
false:
101+
tag: ${{ inputs.from }}
102+
103+
- run: |
104+
docker tag acme/example:${{ steps.context.outputs.tag }}
105+
```
106+
107+
### Implement switch
108+
```yaml
109+
name: Build
110+
on:
111+
pull_request:
112+
branches: [ 'main' ]
113+
types: [opened, synchronize, reopened]
114+
push:
115+
branches: [ main ]
116+
release:
117+
types: [published]
118+
119+
jobs:
120+
context:
121+
runs-on: ubuntu-latest
122+
steps:
123+
- name: Context
124+
id: controller
125+
uses: cloudposse/github-action-yaml-config-query@main
126+
with:
127+
query: .${{ github.event_name }}
128+
config: |-
129+
pull_request:
130+
build: true
131+
promote: false
132+
test: true
133+
deploy: ["preview"]
134+
push:
135+
build: true
136+
promote: false
137+
test: true
138+
deploy: ["dev"]
139+
release:
140+
build: false
141+
promote: true
142+
test: false
143+
deploy: ["staging", "production"]
68144
outputs:
69-
result: ${{ steps.example.outputs.result1 }}
145+
build: ${{ steps.controlle.outputs.build }}
146+
promote: ${{ steps.controlle.outputs.promote }}
147+
test: ${{ steps.controlle.outputs.test }}
148+
deploy: ${{ steps.controlle.outputs.deploy }}
149+
150+
build:
151+
needs: [context]
152+
if: ${{ needs.context.outputs.build }}
153+
uses: ./.github/workflows/reusable-build.yaml
154+
155+
test:
156+
needs: [context, test]
157+
if: ${{ needs.context.outputs.test }}
158+
uses: ./.github/workflows/reusable-test.yaml
159+
160+
promote:
161+
needs: [context]
162+
if: ${{ needs.context.outputs.promote }}
163+
uses: ./.github/workflows/reusable-promote.yaml
164+
165+
deploy:
166+
needs: [context]
167+
if: ${{ needs.context.outputs.deploy != '[]' }}
168+
strategy:
169+
matrix:
170+
environment: ${{ fromJson(needs.context.outputs.deploy) }}
171+
uses: ./.github/workflows/reusable-deploy.yaml
172+
with:
173+
environment: ${{ matrix.environment }}
70174
```
71175
72176
include:

0 commit comments

Comments
 (0)