Skip to content

Commit b087b3e

Browse files
authored
Fix special chars (#17)
## what * Fix special chars issue
1 parent fc85cad commit b087b3e

File tree

489 files changed

+36766
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

489 files changed

+36766
-65
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Test special chars
2+
on:
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
8+
workflow_dispatch:
9+
inputs:
10+
paths:
11+
description: 'A multiline yaml string of key/value pairs for each Name and Path to include in the comment'
12+
required: false
13+
default: |
14+
Application: application
15+
Dashboard: /dashboard
16+
17+
jobs:
18+
setup:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
target: ["one", "two"]
23+
steps:
24+
- name: Setup
25+
run: echo "Do setup"
26+
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
30+
- uses: ./
31+
id: writer
32+
with:
33+
matrix-step-name: ${{ github.job }}
34+
matrix-key: ${{ matrix.target }}
35+
outputs: |-
36+
result2: ${{ matrix.target }}
37+
test: "comment: URL for deploy: https://frontend-docs-259.website.dev"
38+
test2: "comment: URL for deploy: ' https://frontend-docs-259.website.dev"
39+
test3: ${{ toJson(inputs.paths) }}
40+
41+
- uses: nick-fields/assert-action@v1
42+
with:
43+
expected: ${{ matrix.target }}
44+
actual: ${{ fromJson(steps.writer.outputs.result).result2 }}
45+
46+
- uses: nick-fields/assert-action@v1
47+
with:
48+
expected: ${{ matrix.target }}
49+
actual: ${{ steps.writer.outputs.result2 }}
50+
51+
- uses: nick-fields/assert-action@v1
52+
with:
53+
expected: "comment: URL for deploy: https://frontend-docs-259.website.dev"
54+
actual: ${{ fromJson(steps.writer.outputs.result).test }}
55+
56+
- uses: nick-fields/assert-action@v1
57+
with:
58+
expected: "comment: URL for deploy: https://frontend-docs-259.website.dev"
59+
actual: ${{ steps.writer.outputs.test }}
60+
61+
- uses: nick-fields/assert-action@v1
62+
with:
63+
expected: "comment: URL for deploy: ' https://frontend-docs-259.website.dev"
64+
actual: ${{ fromJson(steps.writer.outputs.result).test2 }}
65+
66+
- uses: nick-fields/assert-action@v1
67+
with:
68+
expected: "comment: URL for deploy: ' https://frontend-docs-259.website.dev"
69+
actual: ${{ steps.writer.outputs.test2 }}
70+
71+
- uses: nick-fields/assert-action@v1
72+
with:
73+
expected: |
74+
Application: application
75+
Dashboard: /dashboard
76+
actual: ${{ fromJson(steps.writer.outputs.result).test3 }}
77+
78+
- uses: nick-fields/assert-action@v1
79+
with:
80+
expected: |
81+
Application: application
82+
Dashboard: /dashboard
83+
actual: ${{ steps.writer.outputs.test3 }}
84+
85+
test:
86+
runs-on: ubuntu-latest
87+
continue-on-error: true
88+
needs: [setup]
89+
steps:
90+
- uses: actions/download-artifact@v3
91+
92+
- id: current
93+
run: |-
94+
echo "result=$(ls | wc -l)" >> $GITHUB_OUTPUT
95+
96+
outputs:
97+
result: "${{ steps.current.outputs.result }}"
98+
99+
assert:
100+
runs-on: ubuntu-latest
101+
needs: [test]
102+
steps:
103+
- uses: nick-fields/assert-action@v1
104+
with:
105+
expected: '2'
106+
actual: "${{ needs.test.outputs.result }}"
107+
108+
109+
teardown:
110+
runs-on: ubuntu-latest
111+
needs: [assert]
112+
if: ${{ always() }}
113+
steps:
114+
- name: Tear down
115+
run: echo "Do Tear down"

.github/workflows/test-validation.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Test validation
2+
on:
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
setup:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Setup
15+
run: echo "Do setup"
16+
17+
test:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
target: ["one", "two"]
22+
continue-on-error: true
23+
needs: [setup]
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
28+
- uses: ./
29+
id: current
30+
with:
31+
matrix-step-name: ${{ github.job }}
32+
matrix-key: ${{ matrix.target }}
33+
outputs: |-
34+
result: ${{ matrix.target }}
35+
test: comment: URL for deploy: https://frontend-docs-259.website.dev
36+
37+
- uses: nick-fields/assert-action@v1
38+
with:
39+
expected: ${{ matrix.target }}
40+
actual: ${{ fromJson(steps.writer.outputs.result).result }}
41+
42+
- uses: nick-fields/assert-action@v1
43+
with:
44+
expected: "comment: URL for deploy: https://frontend-docs-259.website.dev"
45+
actual: ${{ fromJson(steps.writer.outputs.result).test }}
46+
47+
outputs:
48+
result: "${{ steps.current.outcome }}"
49+
50+
assert:
51+
runs-on: ubuntu-latest
52+
needs: [test]
53+
steps:
54+
- uses: nick-fields/assert-action@v1
55+
with:
56+
expected: 'failure'
57+
actual: "${{ needs.test.outputs.result }}"
58+
59+
60+
teardown:
61+
runs-on: ubuntu-latest
62+
needs: [assert]
63+
if: ${{ always() }}
64+
steps:
65+
- name: Tear down
66+
run: echo "Do Tear down"

README.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ usage: |-
9595
matrix-key: ${{ matrix.platform }}
9696
outputs: |-
9797
image: ${{ steps.build.outputs.image }}:${{ steps.build.outputs.tag }}
98+
## Multiline string
99+
tags: ${{ toJson(steps.build.outputs.image) }}
98100
99101
## Read matrix outputs
100102
read:
@@ -195,6 +197,7 @@ usage: |-
195197
196198
outputs:
197199
image: ${{ fromJson(steps.out.outputs.result).image }}
200+
image_alternative: ${{ steps.out.outputs.image }}
198201
```
199202
200203
Then you can use the workflow with matrix

action.yml

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -16,69 +16,7 @@ inputs:
1616
description: "YAML structured map of outputs"
1717
outputs:
1818
result:
19-
description: "Outputs result"
20-
value: "${{ steps.proxy.outputs.result }}"
19+
description: "Outputs result (Deprecated!!!)"
2120
runs:
22-
using: "composite"
23-
steps:
24-
- uses: nick-fields/assert-action@v1
25-
if: ${{ inputs.matrix-key != '' }}
26-
with:
27-
expected: ''
28-
actual: "${{ inputs.matrix-step-name }}"
29-
comparison: notEqual
30-
31-
- uses: nick-fields/assert-action@v1
32-
if: ${{ inputs.matrix-step-name != '' }}
33-
with:
34-
expected: ''
35-
actual: "${{ inputs.matrix-key }}"
36-
comparison: notEqual
37-
38-
- name: 'Install jq 1.6'
39-
uses: dcarbone/[email protected]
40-
with:
41-
version: 1.6
42-
force: 'true'
43-
44-
- name: 'Setup yq'
45-
uses: dcarbone/[email protected]
46-
with:
47-
version: v4.28.1
48-
download-compressed: true
49-
force: true
50-
51-
- shell: bash
52-
id: proxy
53-
run: |-
54-
JSON=$(echo "${{ inputs.outputs }}" | yq '. + {}' -o json | jq . -c -M -e)
55-
echo "result=${JSON}" >> $GITHUB_OUTPUT
56-
57-
- uses: cloudposse/[email protected]
58-
id: mask
59-
with:
60-
query: .${{ inputs.matrix-key == '' }}
61-
config: |-
62-
true:
63-
mask: ". + {}"
64-
false:
65-
mask: "{\"${{ inputs.matrix-key}}\": . + {}}"
66-
67-
- shell: bash
68-
id: write
69-
run: |-
70-
JSON=$(echo "${{ inputs.outputs }}" | yq '${{ steps.mask.outputs.mask }}' -o json | jq . -c -M -e)
71-
echo "result=${JSON}" >> $GITHUB_OUTPUT
72-
73-
- shell: bash
74-
if: ${{ inputs.outputs != '' && inputs.matrix-step-name != '' }}
75-
run: |
76-
echo '${{ steps.write.outputs.result }}' > ${{ inputs.matrix-step-name }}
77-
id: matrix
78-
79-
- uses: actions/upload-artifact@v3
80-
if: ${{ inputs.outputs != '' && inputs.matrix-step-name != '' }}
81-
with:
82-
name: ${{ hashFiles( inputs.matrix-step-name ) || 'none' }}
83-
path: ${{ inputs.matrix-step-name }}
84-
if-no-files-found: warn
21+
using: "node16"
22+
main: "index.js"

index.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const core = require('@actions/core');
2+
const yaml = require('yaml')
3+
const artifact = require('@actions/artifact');
4+
const crypto = require('crypto');
5+
const fs = require('fs');
6+
7+
try {
8+
const step_name = core.getInput('matrix-step-name');
9+
const matrix_key = core.getInput('matrix-key');
10+
const outputs = core.getInput('outputs');
11+
12+
core.debug("step_name:")
13+
core.debug(step_name)
14+
15+
core.debug("matrix_key:")
16+
core.debug(matrix_key)
17+
18+
core.debug("outputs:")
19+
core.debug(outputs)
20+
21+
function isEmptyInput(value) {
22+
return value === null || value.trim() === "";
23+
}
24+
25+
if (isEmptyInput(step_name) && !isEmptyInput(matrix_key)) {
26+
core.setFailed("`matrix-step-name` can not be empty when `matrix-key` specified");
27+
return
28+
}
29+
30+
if (!isEmptyInput(step_name) && isEmptyInput(matrix_key)) {
31+
core.setFailed("`matrix-key` can not be empty when `matrix-step-name` specified");
32+
return
33+
}
34+
35+
if (!isEmptyInput(outputs)) {
36+
try {
37+
yaml.parse(outputs)
38+
}
39+
catch (error) {
40+
message = `Outputs should be valid YAML
41+
---------------------
42+
${outputs}
43+
---------------------
44+
${error}`;
45+
core.setFailed(message);
46+
return
47+
}
48+
}
49+
50+
const outputs_struct = !isEmptyInput(outputs) ? yaml.parse(outputs) : {}
51+
52+
Object.keys(outputs_struct).forEach(function(key, index) {
53+
core.setOutput(key, outputs_struct[key])
54+
});
55+
56+
core.debug("outputs_struct:")
57+
core.debug(outputs_struct)
58+
59+
core.debug("JSON.stringify(outputs_struct):")
60+
core.debug(JSON.stringify(outputs_struct))
61+
62+
core.setOutput('result', JSON.stringify(outputs_struct))
63+
64+
if (!isEmptyInput(outputs)) {
65+
const artifact_content = isEmptyInput(matrix_key) ? outputs_struct : { matrix_key: outputs_struct }
66+
67+
fs.writeFileSync("./" + step_name, JSON.stringify(artifact_content));
68+
const fileBuffer = fs.readFileSync("./" + step_name);
69+
const hashSum = crypto.createHash('sha256');
70+
hashSum.update(fileBuffer);
71+
72+
const hex = hashSum.digest('hex');
73+
74+
const artifactClient = artifact.create()
75+
const artifactName = hex;
76+
const files = [
77+
"./" + step_name,
78+
]
79+
80+
const rootDirectory = '.' // Also possible to use __dirname
81+
const options = {
82+
continueOnError: false
83+
}
84+
85+
const uploadResponse = artifactClient.uploadArtifact(artifactName, files, rootDirectory, options)
86+
}
87+
} catch (error) {
88+
core.setFailed(error.message);
89+
}

node_modules/.bin/rimraf

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/uuid

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)