Skip to content

Commit

Permalink
chore: update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
vicradon committed Aug 9, 2024
1 parent 50ba2fc commit 6357365
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .github/actions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Custom Actions

This directory contains custom actions built to support the workflows in this repo and encourage reusability
1 change: 1 addition & 0 deletions .github/actions/create-env-action/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
50 changes: 50 additions & 0 deletions .github/actions/create-env-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'Create .env file'
description: 'An action that creates an .env file from the provided environment variables'
inputs:
env_file_name:
description: 'The env file name that is created'
default: 'app.env'
APP_NAME:
description: 'The name of the Golang app'
APP_URL:
description: 'The URL of the app'
SERVER_PORT:
description: 'The server port'
DB_NAME:
description: 'The name of the database'
USERNAME:
description: 'The database username'
REDIS_PORT:
description: 'The port for Redis'
REDIS_HOST:
description: 'The host for Redis'
REDIS_DB:
description: 'The Redis database number'
GOOGLE_CLIENT_ID:
description: 'The Google client ID'
GOOGLE_CLIENT_SECRET:
description: 'The Google client secret'
FACEBOOK_CLIENT_ID:
description: 'The Facebook client ID'
FACEBOOK_CLIENT_SECRET:
description: 'The Facebook client secret'
SESSION_SECRET:
description: 'The session secret key'
MAIL_SERVER:
description: 'The mail server'
MAIL_USERNAME:
description: 'The mail server username'
MAIL_PASSWORD:
description: 'The mail server password'
MAIL_PORT:
description: 'The mail server port'
MIGRATE:
description: 'Flag indicating whether to run migrations'

outputs:
env_file:
description: 'The created .env file'

runs:
using: 'node20'
main: 'index.js'
45 changes: 45 additions & 0 deletions .github/actions/create-env-action/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const core = require('@actions/core');
const github = require('@actions/github');
const { writeFile } = require('node:fs/promises');

try {
const envFileName = core.getInput('env_file_name') || "app.env"

const secrets = [
"APP_NAME",
"APP_URL",
"SERVER_PORT",
"DB_NAME",
"USERNAME",
"REDIS_PORT",
"REDIS_HOST",
"REDIS_DB",
"GOOGLE_CLIENT_ID",
"GOOGLE_CLIENT_SECRET",
"FACEBOOK_CLIENT_ID",
"FACEBOOK_CLIENT_SECRET",
"SESSION_SECRET",
"MAIL_SERVER",
"MAIL_USERNAME",
"MAIL_PASSWORD",
"MAIL_PORT",
"MIGRATE"
];


let envString = ""

for (let secret of secrets){
const value = core.getInput(secret)
envString += `${secret}=${value}\n`
}

const envFile = await writeFile(envFileName, envString, { encoding: 'utf-8' })

core.setOutput("env_file", envFile);

const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
} catch (error) {
core.setFailed(error.message);
}
279 changes: 279 additions & 0 deletions .github/actions/create-env-action/package-lock.json

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

Loading

0 comments on commit 6357365

Please sign in to comment.