Files
alfresco-ng2-components/.github/actions/artifact-append/action.yml
dependabot[bot] 91289520de build(deps): bump actions/github-script (#9123)
Bumps [actions/github-script](https://github.com/actions/github-script) from 6.4.1 to 7.0.1.
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](d7906e4ad0...60a0d83039)

---
updated-dependencies:
- dependency-name: actions/github-script
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-04 20:06:48 +01:00

91 lines
2.7 KiB
YAML

name: Append content to Artifact
description: 'Allow the user to append content to an existing artifact'
inputs:
artifact-name:
description: 'The name of the artifact'
required: true
type: string
file-name:
description: 'The name of the file with extension created in the artifact'
required: true
type: string
content:
description: 'The content to append'
type: string
default: ""
runs:
using: "composite"
steps:
- run: echo "Artifact Append"
shell: bash
- name: Download artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: ${{ inputs.artifact-name }}
- run: ls
shell: bash
- name: Append content
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
contentFile: ${{ inputs.content }}
fileName: ${{ inputs.file-name }}
with:
script: |
const fs = require('fs');
const affectedLib = process.env.contentFile;
const fileName = process.env.fileName;
core.info(`Input Filename: ${fileName}`);
core.info(`Input content: ${affectedLib}`);
const content = read(fileName)
core.info(`File content: ${content}`);
appendContent(content, affectedLib);
function read(filename) {
try {
const contentFile = fs.readFileSync(filename, 'utf8').replace('\n','');
return contentFile;
} catch (err) {
core.error(err);
}
}
function write(filename, content) {
try {
fs.writeFileSync(filename, content);
} catch (err) {
core.error(err);
}
}
function appendContent(content, append) {
let changedContent;
const libs = content.split(' ');
if (libs?.length>0) {
if (libs.length === 1 && libs[0] === '') {
libs[0] = append;
changedContent = libs[0];
}
else if (!libs.includes(append)) {
libs.push(append);
changedContent = libs.join(' ');
} else {
core.info(`Lib ${append} already affected`);
}
}
if (changedContent != undefined){
core.info(`File content append: ${changedContent}`)
write(fileName, changedContent);
}
}
- name: Upload artifact
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: ${{ inputs.artifact-name }}
path: ${{ inputs.file-name }}