Skip to content

Commit

Permalink
🚀 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sofianegargouri committed Nov 7, 2023
0 parents commit 85ada6c
Show file tree
Hide file tree
Showing 12 changed files with 1,722 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": "airbnb-base",
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
yarn-error.log
2 changes: 2 additions & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version-tag-prefix ""
version-git-message ":bookmark: %s"
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing

## Drafting a release

```sh
# Build the action
yarn prepare

# Add the files to git
git add .

# Bump the version
yarn version --patch|minor|major

# Push with tags
git push origin main --tags
```
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Deploy on Scalingo

This action will allow you to deploy your app to Scalingo.
It was created to work around the limitation of Scalingo to deploy only after the CI is valid.

> ⚠️ This action works only for Scalingo apps that are linked to GitHub
## Getting started

```yaml
jobs:
deploy:
name: Deploy
runs-on: ubuntu-22.04

steps:
- name: Scalingo Deploy
uses: derniercri/[email protected]
with:
# Required
token: ${{ secrets.SCALINGO_TOKEN }}
appName: YOUR_SCALINGO_APP_NAME
# Optional
apiUrl: "The API URL endpoint, defaults to https://api.osc-fr1.scalingo.com. The list is available here: https://developers.scalingo.com/index#global-information"
branch: The branch to deploy, defaults to the current branch
```
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Scalingo Deploy
description: Trigger a deployment to Scalingo
inputs:
token:
description: Your Scalingo API Token (generate it in your profile settings)
required: true
apiUrl:
description: Scalingo's base API URL
required: true
default: https://api.osc-fr1.scalingo.com
appName:
description: Your Scalingo application name
required: true
branch:
description: The target branch to deploy (defaults to current branch on push and head ref on pull request)
# outputs:
# time: # id of output
# description: 'The time we greeted you'
runs:
using: node20
main: dist/index.js
9 changes: 9 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "scalingo-deploy",
"version": "1.0.0",
"description": "Trigger a deployment to your Scalingo app",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0"
},
"devDependencies": {
"@vercel/ncc": "^0.38.1",
"eslint": "^7.32.0 || ^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.2"
},
"scripts": {
"lint": "yarn eslint 'src/**/*.js'",
"lint:fix": "yarn lint --fix",
"prepare": "yarn ncc build src/index.js -o dist --minify"
}
}
30 changes: 30 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const core = require('@actions/core');
const { apiUrl, token, appName } = require('./constants');

const createDeployment = (bearerToken, branch) => fetch(`${apiUrl}/v1/apps/${appName}/scm_repo_link/manual_deploy`, {
method: 'POST',
body: JSON.stringify({ branch }),
headers: {
Authorization: `Bearer ${bearerToken}`,
'Content-Type': 'application/json',
},
})
.then((res) => {
core.debug(res);
return res;
})
.then((res) => res.json());

const getBearerToken = () => fetch('https://auth.scalingo.com/v1/tokens/exchange', {
method: 'POST',
headers: {
Authorization: `Basic ${Buffer.from(`:${token}`).toString('base64')}`,
'Content-Type': 'application/json',
},
})
.then((res) => res.json());

module.exports = {
createDeployment,
getBearerToken,
};
10 changes: 10 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const core = require('@actions/core');

const apiUrl = core.getInput('apiUrl');
const appName = core.getInput('appName');
const token = core.getInput('token');
const branch = core.getInput('branch');

module.exports = {
apiUrl, appName, branch, token,
};
37 changes: 37 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const core = require('@actions/core');
const github = require('@actions/github');
const { createDeployment, getBearerToken } = require('./api');
const { branch } = require('./constants');

const getBranchToDeploy = () => {
if (branch) {
return branch;
}

const { ref, eventName } = github.context;

if (eventName === 'pull_request') {
return process.env.GITHUB_HEAD_REF;
}

if (ref.startsWith('refs/heads/')) {
return ref.replace('refs/heads/', '');
}
if (ref.startsWith('refs/tags/')) {
return ref.replace('refs/tags/', '');
}
return ref;
};

const main = async () => {
try {
const { token } = await getBearerToken();
const targetBranch = getBranchToDeploy();

await createDeployment(token, targetBranch);
} catch (err) {
core.error(err);
}
};

main();
Loading

0 comments on commit 85ada6c

Please sign in to comment.