Skip to content

Commit 0b61648

Browse files
committed
Add support for detecting values from project properties, and global prefix properties.
1 parent d71878e commit 0b61648

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,23 @@ You can also configure the task itself to specify any of the information set in
4343
### Github Secrets
4444
A large motivation for this was wanting to use Github Actions and still be able to sign my built files. Github does not allow you to have files as [secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) just strings and the workarounds I found involved committing a encrypted form of your keystore to your repo and then decrypting it during an Action. Instead I decided to allow you to specify the keystore file as a base64 encoded string which can be used as a Secret.
4545

46-
You can either manually configure the information by pulling the secrets yourself, or I added a simple helper `jarSigner.fromEnvironmentVariables()` which does the following:
46+
You can either manually configure the information by pulling the secrets yourself, or I added a simple helper `jarSigner.autoDetect()` which which search the following locations in order:
47+
48+
if (prefix != null) {
49+
project.findProperty(prefix + '.' + prop)
50+
System.getenv(prefix + '.' + prop)
51+
}
52+
project.findProperty(prop)
53+
System.getenv(prop)
54+
`prefix` defaults to `project.name` you can override by calling `jarSigner.autoDetect('prefix')`
55+
56+
For the following properties:
4757

4858
jarSigner {
49-
alias = System.env('SIGN_KEY_ALIAS')
50-
keyPass = System.env('SIGN_KEY_PASSWORD')
51-
storePass = System.env('SIGN_KEYSTORE_PASSWORD')
52-
keyStoreData = System.env('SIGN_KEYSTORE_DATA')
59+
alias = 'SIGN_KEY_ALIAS'
60+
keyPass = 'SIGN_KEY_PASSWORD'
61+
storePass = 'SIGN_KEYSTORE_PASSWORD'
62+
keyStoreData = 'SIGN_KEYSTORE_DATA'
5363
}
5464

5565
### Conclusion

src/main/java/net/minecraftforge/gradlejarsigner/GradleJarSignerExtension.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,22 @@ public SignTask sign(Zip task, Closure<SignTask> cfg) {
3333
}
3434

3535
public void fromEnvironmentVariables() {
36-
set("SIGN_KEY_ALIAS", this::setAlias);
37-
set("SIGN_KEY_PASSWORD", this::setKeyPass);
38-
set("SIGN_KEYSTORE_PASSWORD", this::setStorePass);
39-
set("SIGN_KEYSTORE_DATA", this::setKeyStoreData);
36+
fromEnvironmentVariables(project.getName());
37+
}
38+
39+
public void fromEnvironmentVariables(String prefix) {
40+
autoDetect(prefix);
41+
}
42+
43+
public void autoDetect() {
44+
autoDetect(project.getName());
45+
}
46+
47+
public void autoDetect(String prefix) {
48+
set(prefix, "SIGN_KEY_ALIAS", this::setAlias);
49+
set(prefix, "SIGN_KEY_PASSWORD", this::setKeyPass);
50+
set(prefix, "SIGN_KEYSTORE_PASSWORD", this::setStorePass);
51+
set(prefix, "SIGN_KEYSTORE_DATA", this::setKeyStoreData);
4052
}
4153

4254
public void setAlias(String value) {
@@ -77,8 +89,19 @@ void fill(SignTask task) {
7789
task.setKeyStoreFile(this.keyStoreFile);
7890
}
7991

80-
private void set(String key, Consumer<String> prop) {
81-
String data = System.getenv(key);
92+
private void set(String prefix, String key, Consumer<String> prop) {
93+
String data = null;
94+
if (prefix != null) {
95+
data = (String)project.findProperty(prefix + '.' + key);
96+
if (data == null)
97+
data = System.getenv(prefix + '.' + key);
98+
}
99+
100+
if (data == null)
101+
data = (String)project.findProperty(key);
102+
if (data == null)
103+
data = System.getenv(key);
104+
82105
if (data != null)
83106
prop.accept(data);
84107
}

0 commit comments

Comments
 (0)