├── action.yml ├── package.json ├── LICENSE ├── index.js ├── .gitignore ├── .actiongenrc.js └── README.md /action.yml: -------------------------------------------------------------------------------- 1 | name: Persist Data Between Jobs 2 | description: Allows data to be shared between jobs and accessed via env variables and step output 3 | inputs: 4 | data: 5 | description: The data to persist from job 6 | required: false 7 | variable: 8 | description: The variable to be used to access data in other jobs 9 | required: false 10 | retrieve_variables: 11 | description: Comma delimited list of variables to load into job 12 | required: false 13 | runs: 14 | using: node16 15 | main: out/index.js 16 | branding: 17 | icon: save 18 | color: green 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "persist-action-data", 3 | "version": "1.0.0", 4 | "description": "Allows variables to be shared between GitHub Action jobs", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "ncc build index.js -o out" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/nick-invision/persist-action-data.git" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "bugs": { 17 | "url": "https://github.com/nick-invision/persist-action-data/issues" 18 | }, 19 | "homepage": "https://github.com/nick-invision/persist-action-data#readme", 20 | "devDependencies": { 21 | "@actions/artifact": "^1.1.1", 22 | "@actions/core": "^1.10.0", 23 | "@zeit/ncc": "0.22.1", 24 | "action-gen": "1.1.3", 25 | "husky": "^4.3.8", 26 | "rimraf": "3.0.2" 27 | }, 28 | "husky": { 29 | "hooks": { 30 | "pre-commit": "npm run build && git add ." 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Nick Fields 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { join } = require('path'); 2 | const { readFileSync, mkdirSync, writeFileSync } = require('fs'); 3 | const core = require('@actions/core'); 4 | const artifact = require('@actions/artifact'); 5 | const rimraf = require('rimraf'); 6 | 7 | const WORKDIR = join(process.cwd(), '_persist_action_dir'); 8 | 9 | async function storeData(variable, data){ 10 | var client = artifact.create(); 11 | const file = join(WORKDIR, `${variable}.txt`); 12 | 13 | // cleanup old directories if needed 14 | rimraf.sync(WORKDIR); 15 | mkdirSync(WORKDIR); 16 | 17 | writeFileSync(file, data, { encoding: 'utf8' }); 18 | await client.uploadArtifact(variable, [file], process.cwd()) 19 | } 20 | async function loadData(variables){ 21 | var client = artifact.create(); 22 | 23 | // cleanup old directories if needed 24 | rimraf.sync(WORKDIR); 25 | mkdirSync(WORKDIR); 26 | 27 | for (const v of variables) { 28 | let data; 29 | 30 | try { 31 | const file = join(WORKDIR, `${v}.txt`); 32 | await client.downloadArtifact(v); 33 | data = readFileSync(file, { encoding: 'utf8' }).toString(); 34 | } catch (error) { 35 | core.warning(`Variable ${v} not found`) 36 | } 37 | core.setOutput(v, data); 38 | core.exportVariable(v, data); 39 | // store the same data with a fixed prefix so it can be iterated over if needed 40 | core.exportVariable(`persist-action-data-${v}`, data); 41 | } 42 | } 43 | 44 | async function runAction(){ 45 | const inputs = { 46 | data: core.getInput('data'), 47 | variable: core.getInput('variable'), 48 | retrieve: core.getInput('retrieve_variables'), 49 | } 50 | 51 | if (inputs.retrieve) { 52 | const vars = inputs.retrieve.split(',').map(v=>v.trim()); 53 | await loadData(vars) 54 | return; 55 | } 56 | 57 | await storeData(inputs.variable, inputs.data) 58 | } 59 | 60 | runAction().then(() => { 61 | core.info('Action completed successfully'); 62 | }) 63 | .catch(e => { 64 | core.setFailed(e.toString()); 65 | }); 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /.actiongenrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'Persist Data Between Jobs', 3 | description: { 4 | short: 'Allows data to be shared between jobs and accessed via env variables and step output', 5 | }, 6 | inputs: [ 7 | { 8 | id: 'data', 9 | description: { 10 | short: 'The data to persist from job', 11 | }, 12 | required: false, 13 | }, 14 | { 15 | id: 'variable', 16 | description: { 17 | short: 'The variable to be used to access data in other jobs', 18 | }, 19 | required: false, 20 | }, 21 | { 22 | id: 'retrieve_variables', 23 | description: { 24 | short: 'Comma delimited list of variables to load into job', 25 | }, 26 | required: false, 27 | }, 28 | ], 29 | runs: { 30 | using: 'node12', 31 | main: 'out/index.js', 32 | }, 33 | usage: { 34 | examples: [ 35 | { 36 | title: 'Example storing data', 37 | codeLanguage: 'yaml', 38 | codeBlock: ` 39 | - uses: nick-invision/persist-action-data@v1 40 | with: 41 | data: \${{ steps.some-step.output.some-output }} 42 | variable: SOME_STEP_OUTPUT 43 | `.trim(), 44 | }, 45 | { 46 | title: 'Example using data from another job via env variable', 47 | codeLanguage: 'yaml', 48 | codeBlock: ` 49 | - uses: nick-invision/persist-action-data@v1 50 | with: 51 | data: \${{ steps.some-step.output.some-output }} 52 | retrieve_variables: SOME_STEP_OUTPUT, SOME_OTHER_STEP_OUTPUT 53 | - run: echo $SOME_STEP_OUTPUT 54 | `.trim(), 55 | }, 56 | { 57 | title: 'Example using data from another job via output', 58 | codeLanguage: 'yaml', 59 | codeBlock: ` 60 | - uses: nick-invision/persist-action-data@v1 61 | id: global-data 62 | with: 63 | data: \${{ steps.some-step.output.some-output }} 64 | retrieve_variables: SOME_STEP_OUTPUT, SOME_OTHER_STEP_OUTPUT 65 | - run: echo $\{\{ steps.global-data.outputs.SOME_STEP_OUTPUT \}\} 66 | `.trim(), 67 | }, 68 | ], 69 | }, 70 | branding: { 71 | color: 'green', 72 | icon: 'save', 73 | }, 74 | badges: [ 75 | { 76 | displayedText: 'License: MIT', 77 | badgeUrl: 'https://img.shields.io/badge/license-MIT-brightgreen.svg', 78 | link: 'https://opensource.org/licenses/MIT', 79 | }, 80 | ], 81 | }; 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Persist Data Between Jobs 2 | 3 | [![License: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) 4 | 5 | Allows data to be shared between jobs and accessed via env variables and step output 6 | 7 | **NOTE:** Ownership of this project was transferred to my personal account `nick-fields` from my work account `nick-invision`. Details [here](#Ownership) 8 | 9 | --- 10 | 11 | ## **Inputs** 12 | 13 | ### **`data`** 14 | 15 | **Optional** The data to persist from job 16 | 17 | ### **`variable`** 18 | 19 | **Optional** The variable to be used to access data in other jobs 20 | 21 | ### **`retrieve_variables`** 22 | 23 | **Optional** Comma delimited list of variables to load into job 24 | 25 | --- 26 | 27 | ## **Examples** 28 | 29 | ### Example storing data 30 | 31 | ```yaml 32 | - uses: nick-fields/persist-action-data@v1 33 | with: 34 | data: ${{ steps.some-step.output.some-output }} 35 | variable: SOME_STEP_OUTPUT 36 | ``` 37 | 38 | ### Example using data from another job via env variable 39 | 40 | ```yaml 41 | - uses: nick-fields/persist-action-data@v1 42 | with: 43 | data: ${{ steps.some-step.output.some-output }} 44 | retrieve_variables: SOME_STEP_OUTPUT, SOME_OTHER_STEP_OUTPUT 45 | - run: echo $SOME_STEP_OUTPUT 46 | ``` 47 | 48 | ### Example using data from another job via output 49 | 50 | ```yaml 51 | - uses: nick-fields/persist-action-data@v1 52 | id: global-data 53 | with: 54 | data: ${{ steps.some-step.output.some-output }} 55 | retrieve_variables: SOME_STEP_OUTPUT, SOME_OTHER_STEP_OUTPUT 56 | - run: echo ${{ steps.global-data.outputs.SOME_STEP_OUTPUT }} 57 | ``` 58 | 59 | 60 | --- 61 | 62 | ## **Ownership** 63 | 64 | As of 2022/02/15 ownership of this project has been transferred to my personal account `nick-fields` from my work account `nick-invision` due to me leaving InVision. I am the author and have been the primary maintainer since day one and will continue to maintain this as needed. 65 | 66 | No immediate action is required if you rely on this as GitHub handles ownership transfers pretty well. Any current workflow reference to `nick-invision/persist-action-data@` will still work, but will just pull from `nick-fields/persist-action-data@` instead. Who knows how long that will work, so at some point it would be beneficial to update your workflows to reflect the new owner accordingly. 67 | --------------------------------------------------------------------------------