Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Action for validation branch name during deployment workflow #807

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/actions/deployment-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'Deployment validation'
description: 'Validates if deployment action can be run'
inputs:
branch-name:
description: 'The branch name should be validated'
required: true
default: ''
runs:
using: 'node20'
main: 'deployment-action.js'
21 changes: 21 additions & 0 deletions .github/actions/deployment-action/deployment-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as core from "@actions/core";
import * as github from "@actions/github";

const allowed = {
branch: ["master"],
prefix: ["release/"],
};

try {
const ref = github.context.payload.pull_request?.["head"]["ref"] as string | null;
if (ref == null) {
throw new Error("The branch name has not been recognized.");
}

if (allowed.branch.includes(ref) == false && allowed.prefix.includes(ref) == false) {
const message = `Allowing deployment from branch='${allowed.branch.join(', ')}' or with prefix='${allowed.prefix.join(', ')}'.`;
core.setFailed(`'${ref}' branch can't be released. ${message}.`);
}
} catch (error) {
core.setFailed(error.message);
}
237 changes: 237 additions & 0 deletions .github/actions/deployment-action/package-lock.json

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

16 changes: 16 additions & 0 deletions .github/actions/deployment-action/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "deployment-action",
"version": "1.0.0",
"description": "",
"main": "deployment-action.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0"
}
}
7 changes: 7 additions & 0 deletions .github/actions/deployment-action/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"sourceMap": true
}
}
6 changes: 6 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: cd .github/actions/deployment-action && npm i && tsc && cd -
- name: Validate branch name before to start deployment
uses: ./.github/actions/deployment-action

- uses: actions/checkout@v3
- name: Runs the deployment workflow in Bitrise
run: |
Expand Down