Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from codeclimate/npc/update-workflow
Browse files Browse the repository at this point in the history
Prepare action
  • Loading branch information
nporteschaikin committed Aug 1, 2019
2 parents 0cce4e4 + 4295f13 commit 4e809fe
Show file tree
Hide file tree
Showing 145 changed files with 11,827 additions and 89 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/workflow.yml
@@ -1,12 +1,25 @@
on: push


jobs:
build:
name: Build workflow
name: Build stage
runs-on: ubuntu-latest

steps:
send_velocity_deployment:
- uses: ./../../
- name: Send Velocity deployment
- uses: actions/checkout@master

- name: Run `npm build:production`
run: npm run-script build:production

report:
name: Report stage
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@master

- name: Send Velocity deployment
uses: ./
with:
token: ${{ secrets.VELOCITY_DEPLOYMENT_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -38,7 +38,9 @@ bower_components
build/Release

# Dependency directories
node_modules/
# Note: As of now, GitHub requires that actions check in the entire dependency
# tree.
# node_modules/
jspm_packages/

# TypeScript v1 declaration files
Expand Down
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions README.md
@@ -0,0 +1,28 @@
# Velocity deployment reporter

This is a simple GitHub action that will report deployments to [Velocity](https://codeclimate.com/velocity)

### Usage

In your workflow, define a step which refers to the action:

```yml
steps:
# ...
- name: Send Velocity deployment
uses: codeclimate/velocity-deploy-action@master
with:
token: ${{ secrets.VELOCITY_DEPLOYMENT_TOKEN }}
version: ${{ outputs.version }}
environment: ${{ outputs.environment }}
```

There are two possible inputs:

- `token`: (string, required): The Velocity deployment token, which you can find on Velocity's settings. This should be provided as a secret, which you can add by visiting the GitHub repository's settings page.
- `version`: (string) The version tag for the deploy (i.e. `b123`). If this action is triggered on a `deploy` event, it will also try to infer the environment from the event. Please note that the version must be unique for each deployment for the same repository and environment. In other words, if you already deployed a v1.0 for https://github.com/user/project in production, the next deploy for the same repository and environment must have a different version, or no version.
- `environment`: (string) The environment of the deploy (i.e. `production`).

### Copyright

See [LICENSE](LICENSE.md)
10 changes: 7 additions & 3 deletions action.yml
Expand Up @@ -2,9 +2,13 @@ name: Velocity deploy action
description: A GitHub Action for sending deployment information to Velocity.
author: Code Climate
inputs:
myInput:
description: 'Input to use'
default: 'world'
token:
description: "Your Velocity deployment token"
required: true
version:
description: "The version tag for the deploy (i.e. `b123`)"
environment:
description: "The environment of the deploy (i.e. `production`)"
runs:
using: "node12"
main: "lib/main.js"
47 changes: 34 additions & 13 deletions lib/main.js
@@ -1,4 +1,12 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
Expand All @@ -17,21 +25,34 @@ const snakecase_keys_1 = __importDefault(require("snakecase-keys"));
const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
const DEPLOYS_URL = process.env.VELOCITY_DEPLOYS_URL || "https://velocity.codeclimate.com/deploys";
const GITHUB_EVENT_PATH = process.env.GITHUB_EVENT_PATH;
const readEvent = () => camelcase_keys_1.default(JSON.parse(fs_1.readFileSync(GITHUB_EVENT_PATH, "utf8")));
const report = (deploy) => axios_1.default.post(DEPLOYS_URL, snakecase_keys_1.default(Object.assign({}, deploy, { token: process.env.VELOCITY_DEPLOYMENT_TOKEN })));
const main = () => {
const readEvent = () => camelcase_keys_1.default(JSON.parse(fs_1.readFileSync(GITHUB_EVENT_PATH, "utf8")), { deep: true });
const report = (deploy) => axios_1.default.post(DEPLOYS_URL, snakecase_keys_1.default(Object.assign({}, deploy, { token: core.getInput("token") })), {
headers: {
Accept: "application/json",
},
});
const run = () => __awaiter(this, void 0, void 0, function* () {
const event = readEvent();
const deploy = {
revision: process.env.GITHUB_SHA,
branch: process.env.GITHUB_REF.replace("refs/heads", ""),
environment: core.getInput("environment") ||
(event.deployment || {}).environment ||
null,
version: core.getInput("version") || null,
repositoryUrl: event.repository.url,
};
core.debug("Reporting deploy to Velocity...");
core.debug(`revision: ${deploy.revision}`);
core.debug(`branch: ${deploy.branch}`);
core.debug(`environment: ${deploy.environment}`);
core.debug(`version: ${deploy.version}`);
try {
const event = readEvent();
report({
revision: process.env.GITHUB_SHA,
branch: process.env.GITHUB_REF,
environment: core.getInput("environment") || (event.deployment || {}).environment,
version: core.getInput("version"),
repositoryUrl: event.repository.webUrl,
});
yield report(deploy);
core.debug("Reported deploy.");
}
catch (error) {
core.setFailed(error.message);
}
};
main();
});
run();
7 changes: 7 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.

66 changes: 66 additions & 0 deletions node_modules/@actions/core/lib/command.js

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

1 change: 1 addition & 0 deletions node_modules/@actions/core/lib/command.js.map

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

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

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

0 comments on commit 4e809fe

Please sign in to comment.