diff --git a/README.md b/README.md index 2a06fb9..a58191c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This GitHub Action generates Kubernetes YAML files from configuration and enviro ## Usage -To use this action in your GitHub workflow, add the following steps to your `.github/workflows/*.yml` file: +To use this action in your GitHub workflow, add the following steps to your `.gitea/workflows/*.yml` file: ```yaml name: Generate K8s YAML @@ -16,13 +16,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Generate K8s YAML uses: ./ with: instance: 'my-instance' namespace: 'my-namespace' serviceType: 'ClusterIP' + envName: '.env' targetPort: 8080 replicas: 3 registry: 'my-registry' diff --git a/dist/index.js b/dist/index.js index 6442b48..3e796cf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -31123,21 +31123,21 @@ const exit = (msg) => { process.exit(1); }; +const envName = core.getInput("envName") || ".env"; // Load environment variables from the .env file -const envPath = path.join(contextPath, ".env"); +const envPath = path.join(contextPath, envName); log(`envPath: ${envPath}`); -if (fs.existsSync(envPath)) { +let envConfig = {}; +const envExist = fs.existsSync(envPath); +if (envExist) { dotenv.config({ path: envPath }); log("Loaded environment variables from the .env file"); -} else { - exit(`.env file not found at path ${envPath}`); + // Set default values for PORT and HOST if not defined + envConfig = dotenv.parse(fs.readFileSync(envPath)); + log(`envConfig: ${JSON.stringify(envConfig)}`); } -// Set default values for PORT and HOST if not defined -const envConfig = dotenv.parse(fs.readFileSync(envPath)); -log(`envConfig: ${JSON.stringify(envConfig)}`); - // Add PORT and HOST to envConfig if not present envConfig.PORT = parseInt(envConfig.PORT || '3000', 10); log(`envConfig.PORT: ${envConfig.PORT}`); @@ -31231,7 +31231,8 @@ const configMap = { metadata: { ...baseMetadata, name: `${packageJson.name}-config` }, data: envConfig }; -log(`configMap: ${JSON.stringify(configMap)}`); +if (envExist) + log(`configMap: ${JSON.stringify(configMap)}`); // Service const service = { @@ -31304,7 +31305,8 @@ const yamlOptions = { log(`yamlOptions: ${JSON.stringify(yamlOptions)}`); const yamlContents = []; -yamlContents.push(yaml.dump(configMap, yamlOptions)); +if (envExist) + yamlContents.push(yaml.dump(configMap, yamlOptions)); yamlContents.push(yaml.dump(service, yamlOptions)); yamlContents.push(yaml.dump(deployment, yamlOptions)); yamlContents.push(yaml.dump(autoscaler, yamlOptions));