Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
DarqueWarrior committed Jun 22, 2021
0 parents commit ffde132
Show file tree
Hide file tree
Showing 19 changed files with 10,107 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/** -diff linguist-generated=true
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
# Enable version updates for npm
- package-ecosystem: "npm"
# Look for `package.json` and `lock` files in the `root` directory
directory: "/"
# Check the npm registry for updates every day (weekdays)
schedule:
interval: "daily"
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "units-test"
on:
# Triggers the workflow on push
push:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
# unit tests
units:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm ci
- run: npm test

# test action works running from the graph
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v2
# Test that the default version is used
- name: Install default version
uses: ./
if: ${{ matrix.os == 'windows-latest'}}
# Test that explicit version is used
- name: Install specific version
uses: ./
if: ${{ matrix.os != 'windows-latest'}}
with:
version: 1.0.0
- name: Run Dapr
run: dapr --version
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
node_modules/

# Editors
.vscode/
.idea/
*.iml

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Other Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @actions/actions-runtime
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 GitHub Actions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Setup Dapr CLI

## Install a specific version of Dapr CLI on a GitHub Actions runner

Acceptable values are any semantic version string like 1.2.0. Use this action in workflow to define which version of Dapr will be used.

```yaml
- uses: dapr/setup-dapr@v1
with:
version: '<version>' # default is 1.2.0
id: install
```
The cached Dapr CLI path is added to the PATH environment variable as well as stored in the dapr-path output variable.
Refer to the action metadata file for details about all the inputs <https://github.com/dapr/setup-dapr/blob/trunk/action.yml>
## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit <https://cla.opensource.microsoft.com>.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
162 changes: 162 additions & 0 deletions action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
const fs = require("fs");
const util = require("util");
const path = require("path");
const core = require("@actions/core");
const tc = require("@actions/tool-cache");

// The name of the tool we are installing with this action.
const toolName = "dapr";

// Base form of the the URL to download the release archives. As long as this
// does not change this will be able to download any version the CLI.
const baseURL = "https://github.com/dapr/cli/releases/download/v";

// Returns the URL used to download a specific version of the Dapr CLI for a
// specific platform.
function getDaprDownloadURL(currentOs, version) {
var file = "";
switch (currentOs) {
case "Linux":
file = "dapr_linux_amd64.tar.gz";
break;

case "Darwin":
file = "dapr_darwin_amd64.tar.gz";
break;

case "Windows_NT":
default:
file = "dapr_windows_amd64.zip";
break;
}

return util.format("%s%s/%s", baseURL, version, file);
}

// Downloads and extracts the archive to the runner and returns the path.
async function downloadDapr(currentOs, version) {
// See if we have cached this tool already
let cachedToolPath = tc.find(toolName, version);

// If we did not find the tool in the cache download it now.
if (!cachedToolPath) {
let downloadPath;
let downloadUrl = getDaprDownloadURL(currentOs, version);
try {
core.info(`Downloading Dapr from ${downloadUrl}...`);
downloadPath = await tc.downloadTool(downloadUrl);
} catch (exception) {
throw new Error(
util.format("Failed to download Dapr from location", downloadUrl)
);
}

// (chmod a+rwx) sets permissions so that, User / owner can read, can
// write and can execute. Group can read, can write and can execute.
// Others can read, can write and can execute.
fs.chmodSync(downloadPath, "777");

// Stores the path where the archive was extracted
let installedToolPath;
if (currentOs === "Windows_NT") {
installedToolPath = await tc.extractZip(downloadPath);
} else {
// Both Linux and macOS use a .tar.gz file
installedToolPath = await tc.extractTar(downloadPath);
}

// Cache to tool so we do not have to download multiple times
cachedToolPath = await tc.cacheDir(installedToolPath, toolName, version);
}

// Get the full path to the executable
const toolPath = findTool(currentOs, cachedToolPath);
if (!toolPath) {
throw new Error(
util.format("Dapr executable not found in path", cachedToolPath)
);
}

core.info(`Dapr installed to ${toolPath}...`);

// (chmod a+rwx) sets permissions so that, User / owner can read, can
// write and can execute. Group can read, can write and can execute.
// Others can read, can write and can execute.
fs.chmodSync(toolPath, "777");

return toolPath;
}

// Returns a install path of the desired tool
function findTool(currentOs, rootFolder) {
fs.chmodSync(rootFolder, "777");

// Holds all the paths. The tool might be installed in multiple locations.
var fileList;

// walkSync is recursive which is why we pass in fileList and assign it the
// return value of this function.
fileList = walkSync(
rootFolder,
fileList,
toolName + getExecutableExtension(currentOs)
);

if (!fileList || fileList.length == 0) {
throw new Error(
util.format("Dapr executable not found in path", rootFolder)
);
} else {
// Return the first one we find.
return fileList[0];
}
}

// Returns the full name of the executable with extension if any. On Linux and
// macOS the executable does not have an extension but on Windows it does.
function getExecutableExtension(currentOs) {
return currentOs.match(/^Win/) ? ".exe" : "";
}

// Returns a list of path to the fileToFind in the dir provided.
function walkSync(dir, fileList, fileToFind) {
var files = fs.readdirSync(dir);

fileList = fileList || [];
files.forEach(function (file) {
if (fs.statSync(path.join(dir, file)).isDirectory()) {
fileList = walkSync(path.join(dir, file), fileList, fileToFind);
} else {
core.debug(file);
if (file == fileToFind) {
fileList.push(path.join(dir, file));
}
}
});

return fileList;
}

// The main function of this action. After the archive is downloaded and
// extracted this function adds it location to the path. This will make sure
// other steps in your workflow will be able to call the Dapr CLI.
async function run(currentOs, version) {
let cachedPath = await downloadDapr(currentOs, version);

if (!process.env["PATH"].startsWith(path.dirname(cachedPath))) {
core.addPath(path.dirname(cachedPath));
}

console.log(
`Dapr CLI version: '${version}' has been cached at ${cachedPath}`
);

// set a an output of this action incase future steps need the path to the tool.
core.setOutput("dapr-path", cachedPath);
}

module.exports = {
run: run,
downloadDapr: downloadDapr,
getDaprDownloadURL: getDaprDownloadURL,
};
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'Dapr tool installer'
description: 'Install a specific version of Dapr CLI. Acceptable values are semantic version string like 1.2.0'
inputs:
version:
description: 'Version of Dapr CLI to install'
required: false
default: '1.2.0'
outputs:
dapr-path:
description: 'Path to the Dapr CLI'
branding:
color: green
icon: server
runs:
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit ffde132

Please sign in to comment.