Define YAML document, filter it with JSON query and get result as outputs
Utility action allow to declare YAML structured document as an input and get it's part as the action outputs referenced using JQ.
This action is useful in simplifing complext GitHub action workflows in different ways. For examples follow usage section.
There is an issue The query contains true
or false
fails with an error.
A workaround is to use a quote around "true" and
"false" in a query.
To migrate from v0
to v1
, quote in your queries all true
/false
and Github actions substitutions resovled to the values.
query: .true
replace withquery: ."true"
query: .${{ inputs.from == '' }}
replace withquery: ."${{ inputs.from == '' }}"
name: Pull Request
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]
jobs:
demo:
runs-on: ubuntu-latest
steps:
- name: Context
id: context
uses: cloudposse/github-action-yaml-config-query@main
with:
config: |
image: acme/example
tag: sha-${{ github.sha }}
- run: |
docker run ${{ steps.context.outputs.image }}:${{ steps.context.outputs.tag }}
name: Promote
on:
workflow_call:
inputs:
from:
required: false
type: string
jobs:
demo:
runs-on: ubuntu-latest
steps:
- name: Context
id: from
uses: cloudposse/github-action-yaml-config-query@main
with:
query: ."${{ inputs.from == '' }}"
config: |-
true:
tag: ${{ github.sha }}
false:
tag: ${{ inputs.from }}
- run: |
docker tag acme/example:${{ steps.context.outputs.tag }}
name: Build
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened]
push:
branches: [ main ]
release:
types: [published]
jobs:
context:
runs-on: ubuntu-latest
steps:
- name: Context
id: controller
uses: cloudposse/github-action-yaml-config-query@main
with:
query: .${{ github.event_name }}
config: |-
pull_request:
build: true
promote: false
test: true
deploy: ["preview"]
push:
build: true
promote: false
test: true
deploy: ["dev"]
release:
build: false
promote: true
test: false
deploy: ["staging", "production"]
outputs:
build: ${{ steps.controlle.outputs.build }}
promote: ${{ steps.controlle.outputs.promote }}
test: ${{ steps.controlle.outputs.test }}
deploy: ${{ steps.controlle.outputs.deploy }}
build:
needs: [context]
if: ${{ needs.context.outputs.build }}
uses: ./.github/workflows/reusable-build.yaml
test:
needs: [context, test]
if: ${{ needs.context.outputs.test }}
uses: ./.github/workflows/reusable-test.yaml
promote:
needs: [context]
if: ${{ needs.context.outputs.promote }}
uses: ./.github/workflows/reusable-promote.yaml
deploy:
needs: [context]
if: ${{ needs.context.outputs.deploy != '[]' }}
strategy:
matrix:
environment: ${{ fromJson(needs.context.outputs.deploy) }}
uses: ./.github/workflows/reusable-deploy.yaml
with:
environment: ${{ matrix.environment }}
Name | Description | Default | Required |
---|---|---|---|
config | YAML config | N/A | true |
query | JQ Query | . | true |
Check out these related projects.
For additional context, refer to some of these links.
- github-actions-workflows - Reusable workflows for different types of projects
- example-github-action-release-workflow - Example application with complicated release workflow
This project is under active development, and we encourage contributions from our community.
Many thanks to our outstanding contributors:
For π bug reports & feature requests, please use the issue tracker.
In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
- Review our Code of Conduct and Contributor Guidelines.
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull Request so that we can review your changes
NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!
Join our Open Source Community on Slack. It's FREE for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally sweet infrastructure.
Sign up for our newsletter and join 3,000+ DevOps engineers, CTOs, and founders who get insider access to the latest DevOps trends, so you can always stay in the know. Dropped straight into your Inbox every week β and usually a 5-minute read.
Join us every Wednesday via Zoom for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a live Q&A that you canβt find anywhere else. It's FREE for everyone!
Preamble to the Apache License, Version 2.0
Complete license is available in the LICENSE
file.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
All other trademarks referenced herein are the property of their respective owners.
Copyright Β© 2017-2024 Cloud Posse, LLC