Skip to content

Commit

Permalink
Fix special chars (#17)
Browse files Browse the repository at this point in the history
## what
* Fix special chars issue
  • Loading branch information
goruha authored Apr 14, 2023
1 parent fc85cad commit b087b3e
Show file tree
Hide file tree
Showing 489 changed files with 36,766 additions and 65 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/test-special-chars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Test special chars
on:
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
# #
# # Added pull_request to register workflow from the PR.
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
# pull_request: {}
workflow_dispatch:
inputs:
paths:
description: 'A multiline yaml string of key/value pairs for each Name and Path to include in the comment'
required: false
default: |
Application: application
Dashboard: /dashboard
jobs:
setup:
runs-on: ubuntu-latest
strategy:
matrix:
target: ["one", "two"]
steps:
- name: Setup
run: echo "Do setup"

- name: Checkout
uses: actions/checkout@v3

- uses: ./
id: writer
with:
matrix-step-name: ${{ github.job }}
matrix-key: ${{ matrix.target }}
outputs: |-
result2: ${{ matrix.target }}
test: "comment: URL for deploy: https://frontend-docs-259.website.dev"
test2: "comment: URL for deploy: ' https://frontend-docs-259.website.dev"
test3: ${{ toJson(inputs.paths) }}
- uses: nick-fields/assert-action@v1
with:
expected: ${{ matrix.target }}
actual: ${{ fromJson(steps.writer.outputs.result).result2 }}

- uses: nick-fields/assert-action@v1
with:
expected: ${{ matrix.target }}
actual: ${{ steps.writer.outputs.result2 }}

- uses: nick-fields/assert-action@v1
with:
expected: "comment: URL for deploy: https://frontend-docs-259.website.dev"
actual: ${{ fromJson(steps.writer.outputs.result).test }}

- uses: nick-fields/assert-action@v1
with:
expected: "comment: URL for deploy: https://frontend-docs-259.website.dev"
actual: ${{ steps.writer.outputs.test }}

- uses: nick-fields/assert-action@v1
with:
expected: "comment: URL for deploy: ' https://frontend-docs-259.website.dev"
actual: ${{ fromJson(steps.writer.outputs.result).test2 }}

- uses: nick-fields/assert-action@v1
with:
expected: "comment: URL for deploy: ' https://frontend-docs-259.website.dev"
actual: ${{ steps.writer.outputs.test2 }}

- uses: nick-fields/assert-action@v1
with:
expected: |
Application: application
Dashboard: /dashboard
actual: ${{ fromJson(steps.writer.outputs.result).test3 }}

- uses: nick-fields/assert-action@v1
with:
expected: |
Application: application
Dashboard: /dashboard
actual: ${{ steps.writer.outputs.test3 }}

test:
runs-on: ubuntu-latest
continue-on-error: true
needs: [setup]
steps:
- uses: actions/download-artifact@v3

- id: current
run: |-
echo "result=$(ls | wc -l)" >> $GITHUB_OUTPUT
outputs:
result: "${{ steps.current.outputs.result }}"

assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v1
with:
expected: '2'
actual: "${{ needs.test.outputs.result }}"


teardown:
runs-on: ubuntu-latest
needs: [assert]
if: ${{ always() }}
steps:
- name: Tear down
run: echo "Do Tear down"
66 changes: 66 additions & 0 deletions .github/workflows/test-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test validation
on:
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
# #
# # Added pull_request to register workflow from the PR.
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
# pull_request: {}
workflow_dispatch: {}

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Setup
run: echo "Do setup"

test:
runs-on: ubuntu-latest
strategy:
matrix:
target: ["one", "two"]
continue-on-error: true
needs: [setup]
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: ./
id: current
with:
matrix-step-name: ${{ github.job }}
matrix-key: ${{ matrix.target }}
outputs: |-
result: ${{ matrix.target }}
test: comment: URL for deploy: https://frontend-docs-259.website.dev
- uses: nick-fields/assert-action@v1
with:
expected: ${{ matrix.target }}
actual: ${{ fromJson(steps.writer.outputs.result).result }}

- uses: nick-fields/assert-action@v1
with:
expected: "comment: URL for deploy: https://frontend-docs-259.website.dev"
actual: ${{ fromJson(steps.writer.outputs.result).test }}

outputs:
result: "${{ steps.current.outcome }}"

assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v1
with:
expected: 'failure'
actual: "${{ needs.test.outputs.result }}"


teardown:
runs-on: ubuntu-latest
needs: [assert]
if: ${{ always() }}
steps:
- name: Tear down
run: echo "Do Tear down"
3 changes: 3 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ usage: |-
matrix-key: ${{ matrix.platform }}
outputs: |-
image: ${{ steps.build.outputs.image }}:${{ steps.build.outputs.tag }}
## Multiline string
tags: ${{ toJson(steps.build.outputs.image) }}
## Read matrix outputs
read:
Expand Down Expand Up @@ -195,6 +197,7 @@ usage: |-
outputs:
image: ${{ fromJson(steps.out.outputs.result).image }}
image_alternative: ${{ steps.out.outputs.image }}
```
Then you can use the workflow with matrix
Expand Down
68 changes: 3 additions & 65 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,7 @@ inputs:
description: "YAML structured map of outputs"
outputs:
result:
description: "Outputs result"
value: "${{ steps.proxy.outputs.result }}"
description: "Outputs result (Deprecated!!!)"
runs:
using: "composite"
steps:
- uses: nick-fields/assert-action@v1
if: ${{ inputs.matrix-key != '' }}
with:
expected: ''
actual: "${{ inputs.matrix-step-name }}"
comparison: notEqual

- uses: nick-fields/assert-action@v1
if: ${{ inputs.matrix-step-name != '' }}
with:
expected: ''
actual: "${{ inputs.matrix-key }}"
comparison: notEqual

- name: 'Install jq 1.6'
uses: dcarbone/[email protected]
with:
version: 1.6
force: 'true'

- name: 'Setup yq'
uses: dcarbone/[email protected]
with:
version: v4.28.1
download-compressed: true
force: true

- shell: bash
id: proxy
run: |-
JSON=$(echo "${{ inputs.outputs }}" | yq '. + {}' -o json | jq . -c -M -e)
echo "result=${JSON}" >> $GITHUB_OUTPUT
- uses: cloudposse/[email protected]
id: mask
with:
query: .${{ inputs.matrix-key == '' }}
config: |-
true:
mask: ". + {}"
false:
mask: "{\"${{ inputs.matrix-key}}\": . + {}}"
- shell: bash
id: write
run: |-
JSON=$(echo "${{ inputs.outputs }}" | yq '${{ steps.mask.outputs.mask }}' -o json | jq . -c -M -e)
echo "result=${JSON}" >> $GITHUB_OUTPUT
- shell: bash
if: ${{ inputs.outputs != '' && inputs.matrix-step-name != '' }}
run: |
echo '${{ steps.write.outputs.result }}' > ${{ inputs.matrix-step-name }}
id: matrix

- uses: actions/upload-artifact@v3
if: ${{ inputs.outputs != '' && inputs.matrix-step-name != '' }}
with:
name: ${{ hashFiles( inputs.matrix-step-name ) || 'none' }}
path: ${{ inputs.matrix-step-name }}
if-no-files-found: warn
using: "node16"
main: "index.js"
89 changes: 89 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const core = require('@actions/core');
const yaml = require('yaml')
const artifact = require('@actions/artifact');
const crypto = require('crypto');
const fs = require('fs');

try {
const step_name = core.getInput('matrix-step-name');
const matrix_key = core.getInput('matrix-key');
const outputs = core.getInput('outputs');

core.debug("step_name:")
core.debug(step_name)

core.debug("matrix_key:")
core.debug(matrix_key)

core.debug("outputs:")
core.debug(outputs)

function isEmptyInput(value) {
return value === null || value.trim() === "";
}

if (isEmptyInput(step_name) && !isEmptyInput(matrix_key)) {
core.setFailed("`matrix-step-name` can not be empty when `matrix-key` specified");
return
}

if (!isEmptyInput(step_name) && isEmptyInput(matrix_key)) {
core.setFailed("`matrix-key` can not be empty when `matrix-step-name` specified");
return
}

if (!isEmptyInput(outputs)) {
try {
yaml.parse(outputs)
}
catch (error) {
message = `Outputs should be valid YAML
---------------------
${outputs}
---------------------
${error}`;
core.setFailed(message);
return
}
}

const outputs_struct = !isEmptyInput(outputs) ? yaml.parse(outputs) : {}

Object.keys(outputs_struct).forEach(function(key, index) {
core.setOutput(key, outputs_struct[key])
});

core.debug("outputs_struct:")
core.debug(outputs_struct)

core.debug("JSON.stringify(outputs_struct):")
core.debug(JSON.stringify(outputs_struct))

core.setOutput('result', JSON.stringify(outputs_struct))

if (!isEmptyInput(outputs)) {
const artifact_content = isEmptyInput(matrix_key) ? outputs_struct : { matrix_key: outputs_struct }

fs.writeFileSync("./" + step_name, JSON.stringify(artifact_content));
const fileBuffer = fs.readFileSync("./" + step_name);
const hashSum = crypto.createHash('sha256');
hashSum.update(fileBuffer);

const hex = hashSum.digest('hex');

const artifactClient = artifact.create()
const artifactName = hex;
const files = [
"./" + step_name,
]

const rootDirectory = '.' // Also possible to use __dirname
const options = {
continueOnError: false
}

const uploadResponse = artifactClient.uploadArtifact(artifactName, files, rootDirectory, options)
}
} catch (error) {
core.setFailed(error.message);
}
1 change: 1 addition & 0 deletions node_modules/.bin/rimraf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b087b3e

Please sign in to comment.