From b2a89586c3115d4a4587336fb539dcb041f2ea9d Mon Sep 17 00:00:00 2001 From: Tharun <45945950+Saitharun279@users.noreply.github.com> Date: Sun, 13 Oct 2024 21:53:23 +0530 Subject: [PATCH 1/4] Added environment variables check job in staging github action --- .../workflows/register-commands-staging.yaml | 18 ++++++++++++++++++ environment-variables-validator.sh | 19 +++++++++++++++++++ environment-variables.txt | 10 ++++++++++ 3 files changed, 47 insertions(+) create mode 100644 environment-variables-validator.sh create mode 100644 environment-variables.txt diff --git a/.github/workflows/register-commands-staging.yaml b/.github/workflows/register-commands-staging.yaml index 79b47b12..d1ec599d 100644 --- a/.github/workflows/register-commands-staging.yaml +++ b/.github/workflows/register-commands-staging.yaml @@ -3,7 +3,25 @@ on: push: branches: develop jobs: + Environment-Variables-Check: + runs-on: ubuntu-latest + environment: staging + steps: + - uses: actions/checkout@v2 + - run: bash environment-variables-validator.sh + env: + DISCORD_APPLICATION_ID: ${{secrets.DISCORD_APPLICATION_ID}} + CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}} + DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}} + DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}} + BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}} + DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}} + RDS_SERVERLESS_PUBLIC_KEY: ${{secrets.RDS_SERVERLESS_PUBLIC_KEY}} + CRON_JOBS_PUBLIC_KEY: ${{secrets.CRON_JOBS_PUBLIC_KEY}} + IDENTITY_SERVICE_PUBLIC_KEY: ${{secrets.IDENTITY_SERVICE_PUBLIC_KEY}} + CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}} Register-Commands: + needs: [Environment-Variables-Check] runs-on: ubuntu-latest environment: staging steps: diff --git a/environment-variables-validator.sh b/environment-variables-validator.sh new file mode 100644 index 00000000..07991f1f --- /dev/null +++ b/environment-variables-validator.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +ENV_VARS_FILE="environment-variables.txt" +# Check if the file exists +if [[ ! -f "$ENV_VARS_FILE" ]]; then + echo "File $ENV_VARS_FILE does not exist." + exit 1 +fi + +# Read the file and iterate through each variable name +while IFS= read -r var_name; do + # Check if the variable is set in the environment + if [[ -z "${!var_name}" ]]; then + echo "Environment variable $var_name is not set." + exit 1 # Exit with error if any variable is not set + else + echo "Environment variable $var_name is set." + fi +done < "$ENV_VARS_FILE" \ No newline at end of file diff --git a/environment-variables.txt b/environment-variables.txt new file mode 100644 index 00000000..c9ca0ea8 --- /dev/null +++ b/environment-variables.txt @@ -0,0 +1,10 @@ +DISCORD_PUBLIC_KEY +DISCORD_TOKEN +DISCORD_GUILD_ID +DISCORD_APPLICATION_ID +CURRENT_ENVIRONMENT +BOT_PRIVATE_KEY +RDS_SERVERLESS_PUBLIC_KEY +CRON_JOBS_PUBLIC_KEY +IDENTITY_SERVICE_PUBLIC_KEY +CLOUDFLARE_ACCOUNT_ID \ No newline at end of file From b81f6124d40143e3dde1cc9948d8372e1fbf0777 Mon Sep 17 00:00:00 2001 From: Tharun <45945950+Saitharun279@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:11:42 +0530 Subject: [PATCH 2/4] Reorder env vars and removed success log from bash script --- .../register-commands-production.yaml | 18 ++++++++++++++++++ .../workflows/register-commands-staging.yaml | 10 +++++----- environment-variables-validator.sh | 2 -- environment-variables.txt | 12 ++++++------ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.github/workflows/register-commands-production.yaml b/.github/workflows/register-commands-production.yaml index 161dffdb..d7731afa 100644 --- a/.github/workflows/register-commands-production.yaml +++ b/.github/workflows/register-commands-production.yaml @@ -3,7 +3,25 @@ on: push: branches: main jobs: + Environment-Variables-Check: + runs-on: ubuntu-latest + environment: production + steps: + - uses: actions/checkout@v2 + - run: bash environment-variables-validator.sh + env: + DISCORD_APPLICATION_ID: ${{secrets.DISCORD_APPLICATION_ID}} + DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}} + DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}} + DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}} + CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}} + CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}} + BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}} + RDS_SERVERLESS_PUBLIC_KEY: ${{secrets.RDS_SERVERLESS_PUBLIC_KEY}} + CRON_JOBS_PUBLIC_KEY: ${{secrets.CRON_JOBS_PUBLIC_KEY}} + IDENTITY_SERVICE_PUBLIC_KEY: ${{secrets.IDENTITY_SERVICE_PUBLIC_KEY}} Register-Commands: + needs: [Environment-Variables-Check] runs-on: ubuntu-latest environment: production steps: diff --git a/.github/workflows/register-commands-staging.yaml b/.github/workflows/register-commands-staging.yaml index d1ec599d..72912a10 100644 --- a/.github/workflows/register-commands-staging.yaml +++ b/.github/workflows/register-commands-staging.yaml @@ -11,15 +11,15 @@ jobs: - run: bash environment-variables-validator.sh env: DISCORD_APPLICATION_ID: ${{secrets.DISCORD_APPLICATION_ID}} - CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}} - DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}} + DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}} DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}} + DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}} + CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}} + CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}} BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}} - DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}} RDS_SERVERLESS_PUBLIC_KEY: ${{secrets.RDS_SERVERLESS_PUBLIC_KEY}} CRON_JOBS_PUBLIC_KEY: ${{secrets.CRON_JOBS_PUBLIC_KEY}} IDENTITY_SERVICE_PUBLIC_KEY: ${{secrets.IDENTITY_SERVICE_PUBLIC_KEY}} - CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}} Register-Commands: needs: [Environment-Variables-Check] runs-on: ubuntu-latest @@ -64,4 +64,4 @@ jobs: DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}} RDS_SERVERLESS_PUBLIC_KEY: ${{secrets.RDS_SERVERLESS_PUBLIC_KEY}} CRON_JOBS_PUBLIC_KEY: ${{secrets.CRON_JOBS_PUBLIC_KEY}} - IDENTITY_SERVICE_PUBLIC_KEY: ${{secrets.IDENTITY_SERVICE_PUBLIC_KEY}} + IDENTITY_SERVICE_PUBLIC_KEY: ${{secrets.IDENTITY_SERVICE_PUBLIC_KEY}} \ No newline at end of file diff --git a/environment-variables-validator.sh b/environment-variables-validator.sh index 07991f1f..410ad776 100644 --- a/environment-variables-validator.sh +++ b/environment-variables-validator.sh @@ -13,7 +13,5 @@ while IFS= read -r var_name; do if [[ -z "${!var_name}" ]]; then echo "Environment variable $var_name is not set." exit 1 # Exit with error if any variable is not set - else - echo "Environment variable $var_name is set." fi done < "$ENV_VARS_FILE" \ No newline at end of file diff --git a/environment-variables.txt b/environment-variables.txt index c9ca0ea8..351f988c 100644 --- a/environment-variables.txt +++ b/environment-variables.txt @@ -1,10 +1,10 @@ -DISCORD_PUBLIC_KEY -DISCORD_TOKEN -DISCORD_GUILD_ID DISCORD_APPLICATION_ID -CURRENT_ENVIRONMENT +DISCORD_GUILD_ID +DISCORD_TOKEN +DISCORD_PUBLIC_KEY +CLOUDFLARE_API_TOKEN +CLOUDFLARE_ACCOUNT_ID BOT_PRIVATE_KEY RDS_SERVERLESS_PUBLIC_KEY CRON_JOBS_PUBLIC_KEY -IDENTITY_SERVICE_PUBLIC_KEY -CLOUDFLARE_ACCOUNT_ID \ No newline at end of file +IDENTITY_SERVICE_PUBLIC_KEY \ No newline at end of file From e25fd8e693f527cd34d9a678737693222995c3a6 Mon Sep 17 00:00:00 2001 From: Tharun <45945950+Saitharun279@users.noreply.github.com> Date: Mon, 14 Oct 2024 02:15:05 +0530 Subject: [PATCH 3/4] pre merge-check | format fix --- .github/workflows/register-commands-staging.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/register-commands-staging.yaml b/.github/workflows/register-commands-staging.yaml index 72912a10..77573119 100644 --- a/.github/workflows/register-commands-staging.yaml +++ b/.github/workflows/register-commands-staging.yaml @@ -64,4 +64,4 @@ jobs: DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}} RDS_SERVERLESS_PUBLIC_KEY: ${{secrets.RDS_SERVERLESS_PUBLIC_KEY}} CRON_JOBS_PUBLIC_KEY: ${{secrets.CRON_JOBS_PUBLIC_KEY}} - IDENTITY_SERVICE_PUBLIC_KEY: ${{secrets.IDENTITY_SERVICE_PUBLIC_KEY}} \ No newline at end of file + IDENTITY_SERVICE_PUBLIC_KEY: ${{secrets.IDENTITY_SERVICE_PUBLIC_KEY}} From 863b3a02e319ca2deb6e72f9fe5267fb4a585f2a Mon Sep 17 00:00:00 2001 From: Tharun <45945950+Saitharun279@users.noreply.github.com> Date: Wed, 16 Oct 2024 00:48:35 +0530 Subject: [PATCH 4/4] issue#257 | Add env var to store env var names --- .github/workflows/register-commands-production.yaml | 11 +++++++++++ .github/workflows/register-commands-staging.yaml | 11 +++++++++++ environment-variables-validator.sh | 13 +++---------- environment-variables.txt | 10 ---------- 4 files changed, 25 insertions(+), 20 deletions(-) delete mode 100644 environment-variables.txt diff --git a/.github/workflows/register-commands-production.yaml b/.github/workflows/register-commands-production.yaml index d7731afa..1cc8a4ba 100644 --- a/.github/workflows/register-commands-production.yaml +++ b/.github/workflows/register-commands-production.yaml @@ -10,6 +10,17 @@ jobs: - uses: actions/checkout@v2 - run: bash environment-variables-validator.sh env: + ENV_VAR_NAMES: | + DISCORD_APPLICATION_ID + DISCORD_GUILD_ID + DISCORD_TOKEN + DISCORD_PUBLIC_KEY + CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID + BOT_PRIVATE_KEY + RDS_SERVERLESS_PUBLIC_KEY + CRON_JOBS_PUBLIC_KEY + IDENTITY_SERVICE_PUBLIC_KEY DISCORD_APPLICATION_ID: ${{secrets.DISCORD_APPLICATION_ID}} DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}} DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}} diff --git a/.github/workflows/register-commands-staging.yaml b/.github/workflows/register-commands-staging.yaml index 77573119..434d9c3b 100644 --- a/.github/workflows/register-commands-staging.yaml +++ b/.github/workflows/register-commands-staging.yaml @@ -10,6 +10,17 @@ jobs: - uses: actions/checkout@v2 - run: bash environment-variables-validator.sh env: + ENV_VAR_NAMES: | + DISCORD_APPLICATION_ID + DISCORD_GUILD_ID + DISCORD_TOKEN + DISCORD_PUBLIC_KEY + CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID + BOT_PRIVATE_KEY + RDS_SERVERLESS_PUBLIC_KEY + CRON_JOBS_PUBLIC_KEY + IDENTITY_SERVICE_PUBLIC_KEY DISCORD_APPLICATION_ID: ${{secrets.DISCORD_APPLICATION_ID}} DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}} DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}} diff --git a/environment-variables-validator.sh b/environment-variables-validator.sh index 410ad776..22067b93 100644 --- a/environment-variables-validator.sh +++ b/environment-variables-validator.sh @@ -1,17 +1,10 @@ #!/bin/bash -ENV_VARS_FILE="environment-variables.txt" -# Check if the file exists -if [[ ! -f "$ENV_VARS_FILE" ]]; then - echo "File $ENV_VARS_FILE does not exist." - exit 1 -fi - -# Read the file and iterate through each variable name -while IFS= read -r var_name; do +for var_name in $ENV_VAR_NAMES; do # Check if the variable is set in the environment if [[ -z "${!var_name}" ]]; then echo "Environment variable $var_name is not set." exit 1 # Exit with error if any variable is not set fi -done < "$ENV_VARS_FILE" \ No newline at end of file +done +echo "All Environment variables are set." diff --git a/environment-variables.txt b/environment-variables.txt deleted file mode 100644 index 351f988c..00000000 --- a/environment-variables.txt +++ /dev/null @@ -1,10 +0,0 @@ -DISCORD_APPLICATION_ID -DISCORD_GUILD_ID -DISCORD_TOKEN -DISCORD_PUBLIC_KEY -CLOUDFLARE_API_TOKEN -CLOUDFLARE_ACCOUNT_ID -BOT_PRIVATE_KEY -RDS_SERVERLESS_PUBLIC_KEY -CRON_JOBS_PUBLIC_KEY -IDENTITY_SERVICE_PUBLIC_KEY \ No newline at end of file