Skip to content

Commit

Permalink
Add support for deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
lfraile committed May 10, 2020
1 parent dfe0ae5 commit b8afa7c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Please read [Esquio readthedocs](https://esquio.readthedocs.io/en/latest/) first
- **esquio-api-key**: API key to authenticate to esquio. Recommended to store as [Github secret](https://help.github.com/en/github/automating-your-workflow-with-github-actions/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables)
- **product-name**: Name of the product to which the feature belongs.
- **feature-name**: Name of the feature to enable.
- **deployment-name**: Name of the deplyment you want to set the value for (if you are using rings, otherwise leave empty)

## Example

Expand All @@ -22,4 +23,5 @@ Please read [Esquio readthedocs](https://esquio.readthedocs.io/en/latest/) first
esquio-api-key: ${{ secrets.apikey }}
product-name: 'Default'
feature-name: 'MatchScore'
deployment-name: 'Tests'
```
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
feature-name:
description: 'Feature name'
required: true
deployment-name:
required: false
description: 'Name of the deplyment you want to set the value for (if you are using rings, otherwise leave empty)'
runs:
using: 'node12'
main: 'lib/main.js'
7 changes: 4 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ function run() {
const esquioApiKey = core.getInput('esquio-api-key');
const productName = core.getInput('product-name');
const featureName = core.getInput('feature-name');
yield rolloutFeature(url.parse(esquioUrl), esquioApiKey, productName, featureName);
const deploymentName = core.getInput('deployment-name');
yield rolloutFeature(url.parse(esquioUrl), esquioApiKey, productName, featureName, deploymentName);
}
catch (error) {
core.setFailed(error.message);
}
});
}
function rolloutFeature(esquioUrl, esquioApiKey, productName, featureName) {
function rolloutFeature(esquioUrl, esquioApiKey, productName, featureName, deploymentName) {
return __awaiter(this, void 0, void 0, function* () {
const options = {
hostname: esquioUrl.host,
path: `/api/products/${productName}/features/${featureName}/Rollout?apikey=${esquioApiKey}`,
path: `/api/products/${productName}/deployments/${deploymentName}/features/${featureName}/Rollout?apikey=${esquioApiKey}`,
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ async function run() {
const esquioApiKey = core.getInput('esquio-api-key');
const productName = core.getInput('product-name');
const featureName = core.getInput('feature-name');
const deploymentName = core.getInput('deployment-name');

await rolloutFeature(url.parse(esquioUrl), esquioApiKey, productName, featureName);
await rolloutFeature(url.parse(esquioUrl), esquioApiKey, productName, featureName, deploymentName);
} catch (error) {
core.setFailed(error.message);
}
}

async function rolloutFeature(esquioUrl: url.UrlWithStringQuery, esquioApiKey: string, productName: string, featureName: string) {
async function rolloutFeature(esquioUrl: url.UrlWithStringQuery, esquioApiKey: string, productName: string, featureName: string, deploymentName: string) {
const options = {
hostname: esquioUrl.host,
path: `/api/products/${productName}/features/${featureName}/Rollout?apikey=${esquioApiKey}`,
path: `/api/products/${productName}/deployments/${deploymentName}/features/${featureName}/Rollout?apikey=${esquioApiKey}`,
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down

0 comments on commit b8afa7c

Please sign in to comment.