generated from actions/container-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from RaftechNL/initial-release
Initial release
- Loading branch information
Showing
5 changed files
with
157 additions
and
14 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
# Container image that runs your code | ||
FROM alpine:3.10 | ||
|
||
COPY LICENSE README.md / | ||
|
||
# Copies your code file from your action repository to the filesystem path `/` of the container | ||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
# Install yq 4.34.1 | ||
COPY --from=mikefarah/yq@sha256:1628fe407628354ff041878c26d934922d672a5a76637ea6898b0d4dd8c9d6cd /usr/bin/yq /usr/bin/yq | ||
|
||
# Code file to execute when the docker container starts up (`entrypoint.sh`) | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,64 @@ | ||
# Container Action Template | ||
|
||
To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/). | ||
![Logo](https://img.raftech.nl/white_logo_color1_background.png) | ||
|
||
For info on how to build your first Container action, see the [toolkit docs folder](https://github.com/actions/toolkit/blob/master/docs/container-action.md). | ||
Github Action allowing for dynamic & path based export of properties from YAML files using YQ under the hood. | ||
|
||
## inputs | ||
|
||
| Key | Description | Required | Default Value | | ||
| -------------------- | ----------------------------------------- | -------- | ------------- | | ||
| source-file | Path to file to be used as source | true | N/A | | ||
| yaml-properties | YAML properties to be exported | true | N/A | | ||
| export-to-ci-env | Export to environment variables in the CI | false | "false" | | ||
| export-to-ci-outputs | Export to action outputs in the CI | false | "false" | | ||
| export-to-env-file | Export to env file | false | "false" | | ||
| prefix | Prefix to be used for the exported values | false | "" | | ||
| env-file | Path/Name of the env file to be created | false | "env.export" | | ||
|
||
|
||
|
||
## Usage/Examples | ||
|
||
```yaml | ||
jobs: | ||
export-from-yaml: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: "Export from YAML" | ||
uses: RaftechNL/[email protected] | ||
id: export-to-yaml | ||
with: | ||
source-file: .cicd/metadata.yaml | ||
export-to-ci-env: "true" | ||
export-to-ci-outputs: "true" | ||
export-to-env-file: "true" | ||
prefix: "SSM_" | ||
yaml-properties: | | ||
APP_NAME=.app.name | ||
APP_STAGE=.app.brand | ||
- name: "show output" | ||
run: | | ||
echo "app name: ${{ steps.export-to-yaml.outputs.APP_NAME }}" | ||
echo "stage: ${{ steps.export-to-yaml.outputs.APP_STAGE }}" | ||
echo "app name: ${{ env.SSM_APP_NAME }}" | ||
echo "stage: ${{ env.SSM_APP_STAGE }}" | ||
cat env.export | ||
``` | ||
## License | ||
[![License](https://img.shields.io/github/license/raftechnl/action-yaml-exporter)](./LICENSE) | ||
| | ||
## Contributing | ||
Contributions are always welcome! | ||
## Authors | ||
- [@rafpe](https://www.github.com/rafpe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
name: 'Container Action Template' | ||
description: 'Get started with Container actions' | ||
author: 'GitHub' | ||
inputs: | ||
myInput: | ||
description: 'Input to use' | ||
default: 'world' | ||
name: 'action-yaml-exporter' | ||
description: 'Export YAML properties' | ||
inputs: | ||
source-file: | ||
description: 'Path to file to be used as source' | ||
required: true | ||
yaml-properties: | ||
description: 'YAML properties to be exported' | ||
required: true | ||
export-to-ci-env: | ||
description: 'Export to environment variables in the CI' | ||
required: false | ||
default: "false" | ||
export-to-ci-outputs: | ||
description: 'Export to action outputs in the CI' | ||
required: false | ||
default: "false" | ||
export-to-env-file: | ||
description: 'Export to env file' | ||
required: false | ||
default: "false" | ||
prefix: | ||
description: 'Prefix to be used for the exported values' | ||
required: false | ||
default: "" | ||
env-file: | ||
description: 'Path/Name of the env file to be created' | ||
required: false | ||
default: "env.export" | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.myInput }} | ||
- ${{ inputs.source-file }} | ||
- ${{ inputs.yaml-properties }} | ||
- ${{ inputs.export-to-ci-env }} | ||
- ${{ inputs.export-to-ci-outputs }} | ||
- ${{ inputs.export-to-env-file }} | ||
- ${{ inputs.env-file }} | ||
- ${{ inputs.prefix }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,55 @@ | ||
#!/bin/sh -l | ||
|
||
echo "hello $1" | ||
SOURCE_FILE=$1 | ||
YAML_PROPERTIES=$2 | ||
EXPORT_TO_CI_ENV=$3 | ||
EXPORT_TO_CI_OUTPUTS=$4 | ||
EXPORT_TO_ENV_FILE=$5 | ||
ENV_FILE=$6 | ||
PREFIX=$7 | ||
|
||
echo "SOURCE_FILE: $SOURCE_FILE" | ||
echo "YAML_PROPERTIES: $YAML_PROPERTIES" | ||
echo "EXPORT_TO_CI_ENV: $EXPORT_TO_CI_ENV" | ||
echo "EXPORT_TO_CI_OUTPUTS: $EXPORT_TO_CI_OUTPUTS" | ||
echo "EXPORT_TO_ENV_FILE: $EXPORT_TO_ENV_FILE" | ||
echo "ENV_FILE: $ENV_FILE" | ||
echo "PREFIX: $PREFIX" | ||
|
||
|
||
#YQ_PATH=$1 /usr/bin/yq 'eval(strenv(YQ_PATH))' .cicd/metadata.yaml | ||
|
||
#echo $2 | ||
|
||
for i in $YAML_PROPERTIES | ||
do | ||
echo "Now processing... $i" | ||
echo $i | ||
|
||
# Splitting the string into key and value | ||
key=$(echo $i | cut -d '=' -f 1) | ||
value=$(echo $i | cut -d '=' -f 2) | ||
|
||
echo "Key: $key" | ||
echo "Value: $value" | ||
|
||
YQ_RESULT=$(YQ_PATH=$value /usr/bin/yq 'eval(strenv(YQ_PATH))' "${SOURCE_FILE}" ) | ||
echo $YQ_RESULT | ||
|
||
if [ "$EXPORT_TO_CI_ENV" = "true" ]; then | ||
echo "Exporting to CI env" | ||
echo "${PREFIX}${key}=$YQ_RESULT" >> $GITHUB_ENV | ||
fi | ||
|
||
if [ "$EXPORT_TO_CI_OUTPUTS" = "true" ]; then | ||
echo "Exporting to CI outputs" | ||
echo "$key=$YQ_RESULT" >> $GITHUB_OUTPUT | ||
fi | ||
|
||
if [ "$EXPORT_TO_ENV_FILE" = "true" ]; then | ||
echo "Exporting to env file" | ||
echo "${PREFIX}${key}=$YQ_RESULT" >> $ENV_FILE | ||
fi | ||
|
||
done | ||
|