-
Notifications
You must be signed in to change notification settings - Fork 32
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
.pawn constants values not being proxied to source files #511
Comments
Well you should instead make use of .env files which sampctl autoloads and use the pawn-env plugin https://github.com/dakyskye/pawn-env Because |
@ADRFranklin Thanks for your reply, correct, in my real codebase I don't have these constants in the pawn.json file, but rather as docker env vars, in my pawn.json I just have: {
"name": "main",
"includes": ["../../legacy"],
"args": ["-;+", "-(+", "-O1", "-Z+"],
"compiler": {},
"constants": {
"MYSQL_HOST": "$MYSQL_HOST",
"MYSQL_PORT": "$MYSQL_PORT",
"MYSQL_USER": "$MYSQL_USER",
"MYSQL_PASS": "$MYSQL_PASS",
"MYSQL_DB": "$MYSQL_DB"
}
}, The snippet I posted was just a reproducible example of the issue with sampctl constants. To be fair I couldn't make it work using pawn compiler directly passing the constants as compiler options. Using env variables also doesn't work. I'll check out the library you provided, cheers. Also about having database connection configuration versioned: It actually depends on the use case right? I assume you're talking about production environment which I obviously agree, but if I have an integration tests setup on my ci workflow where the database schema is short-lived (created/destroyed during the workflow run) and only accessible from the CI tool (i.e. Github Actions), I don't see any harm or potential security issues, I would end up having something like: {
....
"builds": [
{
"name": "live",
"includes": ["../../legacy"],
"args": ["-;+", "-(+", "-O1", "-Z+"],
"compiler": {},
"constants": {
"MYSQL_HOST": "$MYSQL_HOST",
"MYSQL_PORT": "$MYSQL_PORT",
"MYSQL_USER": "$MYSQL_USER",
"MYSQL_PASS": "$MYSQL_PASS",
"MYSQL_DB": "$MYSQL_DB"
}
},
{
"name": "tests",
"includes": ["../../legacy"],
"args": ["-;+", "-(+", "-O1", "-Z+", "-d3"],
"compiler": {},
"constants": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "integration_tests",
"MYSQL_PASS": "integration_tests",
"MYSQL_DB": "integration_tests"
}
}
]
} |
The stuff in |
@ADRFranklin I have no issues when the constant value is a number, however when it's a string it's defined as empty. "constants": {
"MY_CONSTANT_NUMBER": "300", // works
"MY_CONSTANT_STRING": "test" // will output an empty string when running printf("%s", MY_CONSTANT_STRING);
}, |
As a sampctl user
I want to be able to define constants in pawn.json
So that I don't have sensitive information such as database credentials in my .pawn files.
Scenario 1: Works in code ✅
Given a constant as string in a
.pwn
source file.When compiling package with a ubuntu image in a docker container.
Then the compiled .amx file is generated successfully.
Example
package.pwn
Scenario 2: Fails in sampctl ❌
Given a constant as string in
constants
configuration for a build inpawn.json
.When compiling package with a ubuntu image in a docker container.
Then a compiler error
argument type mismatch
is thrown.Example
pawn.json
package.pawn
Error thrown when compiling
Message in console when debugging the constants values.
By the message above I believe the constant values are not being passed somehow to the source code when compiling, either by a mistake on my side (which I can't see where, since the correct values are in pawn compiler args) or something funky in pawn compiler / sampctl. The constants are defined given the build passes, but with an empty value.
I also took a look in pawn's compiler options and by the looks of it I don't think there's anything wrong in sampctl's side, mainly because on how the downstream compiler command is being built, so maybe it could be some platform issue? I have an ARM mac hence I use docker to build my scripts.
The text was updated successfully, but these errors were encountered: