Skip to content

Commit e6fcc3f

Browse files
committed
feat: process env files
1 parent d8a3ff4 commit e6fcc3f

8 files changed

Lines changed: 136 additions & 6 deletions

File tree

.cursorrules

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
8. Support all SettleMint environment variables as optional inputs
99
9. Set predefined contract addresses as environment variables
1010
10. Add auto-login and auto-connect functionality
11-
11. Add comprehensive test coverage for main functionality
12-
12. Configure Renovate to run `npm run package` after dependency updates
13-
13. Create comprehensive README documentation with examples and best practices
11+
11. Process .env files from secrets and add them to GitHub environment
12+
12. Add comprehensive test coverage for main functionality
13+
13. Configure Renovate to run `npm run package` after dependency updates
14+
14. Create comprehensive README documentation with examples and best practices

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,29 @@ All inputs are automatically converted to environment variables with the `SETTLE
139139
- `workspace` → `SETTLEMINT_WORKSPACE`
140140
- `blockchain-network` → `SETTLEMINT_BLOCKCHAIN_NETWORK`
141141

142+
### Environment Files
143+
The action supports loading environment variables from `.env` files. You can provide the content of your env files through the following inputs:
144+
145+
- `dotEnvFile`: Content of your main `.env` file
146+
- `dotEnvLocalFile`: Content of your `.env.local` file
147+
148+
⚠️ **Important**: Always store env file contents in GitHub Secrets:
149+
```yaml
150+
steps:
151+
- uses: settlemint/settlemint-action@main
152+
with:
153+
dotEnvFile: ${{ secrets.MY_ENV_FILE }}
154+
dotEnvLocalFile: ${{ secrets.MY_ENV_LOCAL }}
155+
access-token: ${{ secrets.SETTLEMINT_ACCESS_TOKEN }}
156+
```
157+
158+
The action will process these files and add all variables to the GitHub Actions environment. It handles:
159+
- Comments (lines starting with #)
160+
- Empty lines
161+
- Quoted values
162+
- Values containing = signs
163+
- Trailing comments
164+
142165
## Error Handling
143166

144167
The action will fail if:
@@ -153,6 +176,32 @@ The action will fail if:
153176
- Use GitHub Secrets for sensitive information
154177
- Consider using OIDC for token management in production
155178

179+
## Security Best Practices
180+
181+
### Handling Secrets 🔒
182+
- **NEVER** commit access tokens, private keys or any secrets directly in your workflow files or repository
183+
- **ALWAYS** use GitHub Secrets for sensitive information:
184+
```yaml
185+
# ✅ CORRECT - Using GitHub Secrets
186+
access-token: ${{ secrets.SETTLEMINT_ACCESS_TOKEN }}
187+
188+
# ❌ WRONG - NEVER do this
189+
access-token: "your-token-here" # This is a security risk!
190+
```
191+
- Use GitHub's OIDC (OpenID Connect) for token management in production environments
192+
- Regularly rotate your access tokens and secrets
193+
- Limit secret access to only the necessary workflows and repositories
194+
195+
### Environment Variables
196+
When using .env files:
197+
```yaml
198+
steps:
199+
- uses: settlemint/settlemint-action@main
200+
with:
201+
dotEnvFile: ${{ secrets.ENV_FILE_CONTENT }} # Store as a secret!
202+
access-token: ${{ secrets.SETTLEMINT_ACCESS_TOKEN }}
203+
```
204+
156205
## Contributing
157206

158207
Contributions are welcome! Please read our [Contributing Guide](./.github/CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ inputs:
7575
smart-contract-set:
7676
description: 'SettleMint smart contract set ID'
7777
required: false
78+
dotEnvFile:
79+
description: 'A Github Actions secret containing the .env file, loaded in one go for easy updates'
80+
required: false
81+
dotEnvLocalFile:
82+
description: 'A Github Actions secret containing the .env.local file, loaded in one go for easy updates'
83+
required: false
7884

7985
runs:
8086
using: node20

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "typescript-action",
33
"description": "GitHub Actions TypeScript template",
4-
"version": "0.6.0",
4+
"version": "0.6.1",
55
"author": "",
66
"private": true,
77
"homepage": "https://github.com/actions/typescript-action",

src/main.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,37 @@ const ENV_VARS = [
2121
'smart-contract-set',
2222
];
2323

24+
const ENV_VAR_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*=/;
25+
const QUOTE_PATTERN = /^["'](.*)["']$/;
26+
27+
function processEnvContent(content: string): void {
28+
const lines = content.split('\n');
29+
30+
for (const line of lines) {
31+
const trimmedLine = line.trim();
32+
33+
// Skip empty lines and comments
34+
if (!trimmedLine || trimmedLine.startsWith('#')) {
35+
continue;
36+
}
37+
38+
// Remove trailing comments and trim
39+
const lineWithoutComments = trimmedLine.split('#')[0].trim();
40+
41+
// Check if line matches env var pattern
42+
if (ENV_VAR_PATTERN.test(lineWithoutComments)) {
43+
const [key, ...valueParts] = lineWithoutComments.split('=');
44+
let value = valueParts.join('='); // Rejoin in case value contains =
45+
46+
// Remove surrounding quotes if they exist
47+
value = value.replace(QUOTE_PATTERN, '$1');
48+
49+
// Set in GitHub environment
50+
core.exportVariable(key.trim(), value.trim());
51+
}
52+
}
53+
}
54+
2455
/**
2556
* The main function for the action.
2657
* @returns {Promise<void>} Resolves when the action is complete.
@@ -36,6 +67,17 @@ export async function run(): Promise<void> {
3667
core.debug('Installing SettleMint CLI...');
3768
await exec.exec('npm', ['install', '-g', `@settlemint/sdk-cli@${version}`]);
3869

70+
// Process .env files
71+
const dotEnvFile = core.getInput('dotEnvFile');
72+
if (dotEnvFile) {
73+
processEnvContent(dotEnvFile);
74+
}
75+
76+
const dotEnvLocalFile = core.getInput('dotEnvLocalFile');
77+
if (dotEnvLocalFile) {
78+
processEnvContent(dotEnvLocalFile);
79+
}
80+
3981
// Set optional environment variables
4082
for (const varName of ENV_VARS) {
4183
const value = core.getInput(varName);

0 commit comments

Comments
 (0)