Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-linaro committed Oct 22, 2020
0 parents commit 57832ea
Show file tree
Hide file tree
Showing 368 changed files with 88,653 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Directory push/pop action

This action moves the named directory (if it exists) out of the specified cache directory into the (optionally specified) destination directory. If the destination is not specified, it defaults to `$GITHUB_WORKSPACE`.

When the job that uses this action ends, the action moves the directory back to the cache directory.

## Inputs

### `cacheDirectory`

**Required** Path to the directory used to store directories

### `namedDirectory`

**Required** Name of the directory to move

### `destinationDirectory`

Where to move the named directory to

## Example usage

```yaml
uses: linaro-its/directory-push-pop@v1
with:
cacheDirectory: /srv/cache
namedDirectory: $SITE_URL
```
23 changes: 23 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Directory push/pop
author: Philip Colmer (Linaro Ltd)
branding:
icon: "archive"
color: "green"
description: |
By using a nominated cache directory, this action moves a named directory
out of the cache into the specified destination directory (default is
$GITHUB_WORKSPACE) and then, after the job finishes, moves it back.
inputs:
cacheDirectory:
description: "Path to the directory used to store directories"
required: true
namedDirectory:
description: "Name of the directory to move"
required: true
destinationDirectory:
description: "Where to move the named directory to"
required: false
runs:
using: "node12"
main: 'directory-out.js'
post: 'directory-in.js'
46 changes: 46 additions & 0 deletions directory-in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Reverses what directory-out did, namely moving the
// named directory out of the destination directory back
// into the cache directory.
const core = require('@actions/core');
const fs = require('fs');

function isDirSync(aPath) {
const result = fs.statSync(aPath).isDirectory();
// No error if something exists with the name so
// throw an error if not a directory.
if (!result) {
throw `${aPath} is not a directory`
}
}

function dirExists(aPath) {
try {
const result = fs.statSync(aPath).isDirectory();
if (result) {
return true;
}
} catch (e) {
return false;
}

return false;
}

try {
const cacheDirectory = core.getInput("cacheDirectory", { required: true });
const namedDirectory = core.getInput("namedDirectory", { required: true });
var destinationDirectory = core.getInput("destinationDirectory");
// If the destination directory wasn't specified, default to $GITHUB_WORKSPACE
if (!destinationDirectory) {
destinationDirectory = process.env["GITHUB_WORKSPACE"];
}
// Check that cache and dest exist and are directories.
isDirSync(cacheDirectory);
isDirSync(destinationDirectory);
// If the named directory exists, move it.
if (dirExists(`${destinationDirectory}/${namedDirectory}`)) {
fs.renameSync(`${destinationDirectory}/${namedDirectory}`, `${cacheDirectory}/${namedDirectory}`);
}
} catch (error) {
core.setFailed(error.message);
}
45 changes: 45 additions & 0 deletions directory-out.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Move the named directory (if it exists) out of the cache directory
// into the destination directory.
const core = require('@actions/core');
const fs = require('fs');

function isDirSync(aPath) {
const result = fs.statSync(aPath).isDirectory();
// No error if something exists with the name so
// throw an error if not a directory.
if (!result) {
throw `${aPath} is not a directory`
}
}

function dirExists(aPath) {
try {
const result = fs.statSync(aPath).isDirectory();
if (result) {
return true;
}
} catch (e) {
return false;
}

return false;
}

try {
const cacheDirectory = core.getInput("cacheDirectory", { required: true });
const namedDirectory = core.getInput("namedDirectory", { required: true });
var destinationDirectory = core.getInput("destinationDirectory");
// If the destination directory wasn't specified, default to $GITHUB_WORKSPACE
if (!destinationDirectory) {
destinationDirectory = process.env["GITHUB_WORKSPACE"];
}
// Check that cache and dest exist and are directories.
isDirSync(cacheDirectory);
isDirSync(destinationDirectory);
// If the named directory exists, move it.
if (dirExists(`${cacheDirectory}/${namedDirectory}`)) {
fs.renameSync(`${cacheDirectory}/${namedDirectory}`, `${destinationDirectory}/${namedDirectory}`);
}
} catch (error) {
core.setFailed(error.message);
}
9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

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

147 changes: 147 additions & 0 deletions node_modules/@actions/core/README.md

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

16 changes: 16 additions & 0 deletions node_modules/@actions/core/lib/command.d.ts

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

Loading

0 comments on commit 57832ea

Please sign in to comment.