Skip to content

Commit f7e87f2

Browse files
committed
Merge remote-tracking branch 'origin/master' into release/v5.0.0
2 parents 76e8178 + 2d6c3bc commit f7e87f2

File tree

12 files changed

+395
-33
lines changed

12 files changed

+395
-33
lines changed

action.yml

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,74 @@ inputs:
3131
runs:
3232
using: composite
3333
steps:
34+
- name: Validate Branch/Tag Name
35+
shell: bash
36+
run: |
37+
REF_NAME="${{ github.ref_name }}"
38+
39+
# Check if ref name contains only allowed characters (letters, digits, dash, underscore, dot)
40+
if [[ ! "$REF_NAME" =~ ^[a-zA-Z0-9._-]+$ ]]; then
41+
echo "Branch/tag name '$REF_NAME' contains illegal characters. Only letters, digits, dash (-), underscore (_), and dot (.) are allowed."
42+
echo "Skipping action execution due to invalid ref name."
43+
echo "JDEPLOY_SKIP_EXECUTION=true" >> $GITHUB_ENV
44+
exit 0
45+
fi
46+
47+
# Check if ref name length exceeds 16 characters
48+
if [[ ${#REF_NAME} -gt 16 ]]; then
49+
echo "Branch/tag name '$REF_NAME' is too long (${#REF_NAME} characters). Maximum allowed length is 16 characters."
50+
echo "Skipping action execution due to ref name length limit."
51+
echo "JDEPLOY_SKIP_EXECUTION=true" >> $GITHUB_ENV
52+
exit 0
53+
fi
54+
55+
echo "Branch/tag name '$REF_NAME' is valid."
56+
echo "JDEPLOY_SKIP_EXECUTION=false" >> $GITHUB_ENV
3457
- name: Check Deploy Target
35-
if: ${{ inputs.deploy_target != 'github' && inputs.deploy_target != 'npm' }}
58+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target != 'github' && inputs.deploy_target != 'npm' }}
3659
shell: bash
3760
run: |
3861
echo "Unsupported jdeploy deploy_target: ${{ inputs.deploy_target }}"
3962
exit 1
4063
- name: Check Github Deployment Inputs
41-
if: ${{ inputs.deploy_target == 'github' && inputs.github_token == '' }}
64+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && inputs.github_token == '' }}
4265
shell: bash
4366
run: |
4467
echo "jdeploy action missing github_token parameter"
4568
exit 1
4669
- name: Check npm Deployment Inputs
47-
if: ${{ inputs.deploy_target == 'npm' && inputs.npm_token == '' }}
70+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'npm' && inputs.npm_token == '' }}
4871
shell: bash
4972
run: |
5073
echo "jdeploy action missing npm_token parameter"
5174
exit 1
5275
- name: Set up Git Config
76+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' }}
5377
shell: bash
5478
run: |
5579
git config user.name "GitHub Actions Bot"
5680
git config user.email "<>"
5781
- name: Set up Node
82+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' }}
5883
uses: actions/setup-node@v2
5984
with:
6085
node-version: '16.x'
6186
registry-url: 'https://registry.npmjs.org'
6287

6388
- name: Setup jDeploy Registry
89+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' }}
6490
shell: bash
6591
run: |
6692
echo "JDEPLOY_REGISTRY_URL=${{ inputs.jdeploy_registry_url }}" >> $GITHUB_ENV
6793
6894
- name: Save Original JAVA_HOME
69-
if: env.JAVA_HOME
95+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && env.JAVA_HOME }}
7096
shell: bash
7197
run: |
7298
echo "ORIGINAL_JAVA_HOME=${JAVA_HOME}" >> $GITHUB_ENV
7399
74100
- name: Set up Isolated Java for jDeploy (only for git:// version)
75-
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
101+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && startsWith(inputs.jdeploy_version, 'git://') }}
76102
uses: actions/setup-java@v3
77103
with:
78104
java-version: '11'
@@ -81,29 +107,29 @@ runs:
81107
id: setup-java-jdeploy
82108

83109
- name: Configure Java for jDeploy Only
84-
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
110+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && startsWith(inputs.jdeploy_version, 'git://') }}
85111
shell: bash
86112
run: |
87113
echo "JAVA_HOME_JDEPLOY=${{ steps.setup-java-jdeploy.outputs.path }}" >> $GITHUB_ENV
88114
echo "Using isolated JAVA_HOME for jDeploy: $JAVA_HOME_JDEPLOY"
89115
90116
- name: Restore Original JAVA_HOME
91-
if: ${{ startsWith(inputs.jdeploy_version, 'git://') && env.ORIGINAL_JAVA_HOME }}
117+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && startsWith(inputs.jdeploy_version, 'git://') && env.ORIGINAL_JAVA_HOME }}
92118
shell: bash
93119
run: |
94120
echo "Restoring original JAVA_HOME"
95121
echo "JAVA_HOME=${ORIGINAL_JAVA_HOME}" >> $GITHUB_ENV
96122
97123
- name: Set jDeploy Ref
98-
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
124+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && startsWith(inputs.jdeploy_version, 'git://') }}
99125
shell: bash
100126
run: |
101127
jdeploy_version="${{ inputs.jdeploy_version }}"
102128
JDEPLOY_REF="${jdeploy_version#git://}"
103129
echo "JDEPLOY_REF=$JDEPLOY_REF" >> $GITHUB_ENV
104130
105131
- name: Checkout jDeploy Source
106-
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
132+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && startsWith(inputs.jdeploy_version, 'git://') }}
107133
uses: actions/checkout@v3
108134
with:
109135
repository: 'shannah/jdeploy'
@@ -112,7 +138,7 @@ runs:
112138

113139
- name: Install jDeploy from Source
114140
id: jdeploy_install_source
115-
if: ${{ startsWith(inputs.jdeploy_version, 'git://') }}
141+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && startsWith(inputs.jdeploy_version, 'git://') }}
116142
shell: bash
117143
run: |
118144
export JAVA_HOME="$JAVA_HOME_JDEPLOY"
@@ -130,15 +156,15 @@ runs:
130156

131157
- name: Install jDeploy from NPM
132158
id: jdeploy_install_standard
133-
if: ${{ !startsWith(inputs.jdeploy_version, 'git://') }}
159+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && !startsWith(inputs.jdeploy_version, 'git://') }}
134160
shell: bash
135161
run: |
136162
echo "jdeploy_exec=npx jdeploy@${JDEPLOY_VERSION}" >> $GITHUB_ENV
137163
env:
138164
JDEPLOY_VERSION: ${{ inputs.jdeploy_version }}
139165

140166
- name: Set jdeploy.jdeployVersion for Branch
141-
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'branch' }}
167+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && github.ref_type == 'branch' }}
142168
shell: bash
143169
run: |
144170
if [[ "${{ startsWith(inputs.jdeploy_version, 'git://') }}" == "true" ]]; then
@@ -153,8 +179,8 @@ runs:
153179
GH_TOKEN: ${{ github.actor }}:${{ inputs.github_token }}
154180

155181
- name: Sanitize version name
182+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && github.ref_type == 'tag' }}
156183
shell: bash
157-
if: ${{ github.ref_type == 'tag' }}
158184
run: |
159185
TAG_VERSION=${{ github.ref_name }}
160186
if [[ $TAG_VERSION} = v* ]]; then
@@ -163,7 +189,7 @@ runs:
163189
echo "TAG_VERSION=${TAG_VERSION}" >> $GITHUB_ENV
164190
fi
165191
- name: Prepare Installer Bundles for Branch
166-
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'branch' }}
192+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && github.ref_type == 'branch' }}
167193
shell: bash
168194
run: |
169195
npm pkg set version="0.0.0-${{ github.ref_name }}"
@@ -178,7 +204,7 @@ runs:
178204
GH_TOKEN: ${{ github.actor }}:${{ inputs.github_token }}
179205

180206
- name: Prepare Installer Bundles for Tag
181-
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'tag' }}
207+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && github.ref_type == 'tag' }}
182208
shell: bash
183209
run: |
184210
npm pkg set version="$TAG_VERSION"
@@ -195,15 +221,15 @@ runs:
195221

196222
- name: Publish package-info.json to GitHub
197223
uses: softprops/action-gh-release@v2
198-
if: ${{ inputs.deploy_target == 'github' && inputs.target_repository == github.repository }}
224+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && inputs.target_repository == github.repository }}
199225
with:
200226
token: ${{ inputs.github_token }}
201227
tag_name: "jdeploy"
202228
prerelease: true
203229
files: ./jdeploy/github-release-files/package-info.json
204230

205231
- name: Publish package-info.json to Github
206-
if: ${{ inputs.deploy_target == 'github' && inputs.target_repository != github.repository }}
232+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && inputs.target_repository != github.repository }}
207233
shell: bash
208234
run: |
209235
gh release delete -R '${{ inputs.target_repository }}' jdeploy || true
@@ -213,7 +239,7 @@ runs:
213239

214240
- name: Upload files to GitHub Snapshot Release for Branch
215241
uses: softprops/action-gh-release@v2
216-
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'branch' }}
242+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && github.ref_type == 'branch' }}
217243
with:
218244
tag_name: "${{ github.ref_name }}"
219245
token: "${{ inputs.github_token }}"
@@ -222,7 +248,7 @@ runs:
222248
./jdeploy/github-release-files/*
223249
224250
- name: Upload files to Github Snapshot Release for Branch
225-
if: ${{ inputs.deploy_target == 'github' && inputs.target_repository != github.repository }}
251+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && inputs.target_repository != github.repository }}
226252
shell: bash
227253
run: |
228254
gh release delete -R '${{ inputs.target_repository }}' '${{ github.ref_name }}' || true
@@ -231,7 +257,7 @@ runs:
231257
GH_TOKEN: ${{ inputs.github_token }}
232258

233259
- name: Upload Files to Github Release for Tag
234-
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'tag' && inputs.target_repository == github.repository }}
260+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && github.ref_type == 'tag' && inputs.target_repository == github.repository }}
235261
uses: xresloader/upload-to-github-release@v1.6.0
236262
env:
237263
GITHUB_TOKEN: ${{ inputs.github_token }}
@@ -241,7 +267,7 @@ runs:
241267
overwrite: true
242268

243269
- name: Update release body (for branch release)
244-
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'branch' && inputs.target_repository == github.repository }}
270+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && github.ref_type == 'branch' && inputs.target_repository == github.repository }}
245271
shell: bash
246272
env:
247273
GITHUB_TOKEN: ${{ inputs.github_token }}
@@ -268,7 +294,7 @@ runs:
268294
-d "$BODY_JSON"
269295
270296
- name: Update release body (for tag release)
271-
if: ${{ inputs.deploy_target == 'github' && github.ref_type == 'tag' && inputs.target_repository == github.repository }}
297+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'github' && github.ref_type == 'tag' && inputs.target_repository == github.repository }}
272298
shell: bash
273299
env:
274300
GITHUB_TOKEN: ${{ inputs.github_token }}
@@ -298,7 +324,7 @@ runs:
298324
-d "$BODY_JSON"
299325
300326
- name: Publish to npm
301-
if: ${{ inputs.deploy_target == 'npm' && github.ref_type == 'tag' }}
327+
if: ${{ env.JDEPLOY_SKIP_EXECUTION != 'true' && inputs.deploy_target == 'npm' && github.ref_type == 'tag' }}
302328
shell: bash
303329
env:
304330
NODE_AUTH_TOKEN: ${{ inputs.npm_token }}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package ca.weblite.jdeploy.claude;
2+
3+
import org.apache.commons.io.FileUtils;
4+
import org.apache.http.client.methods.CloseableHttpResponse;
5+
import org.apache.http.client.methods.HttpGet;
6+
import org.apache.http.impl.client.CloseableHttpClient;
7+
import org.apache.http.impl.client.HttpClients;
8+
import org.apache.http.util.EntityUtils;
9+
10+
import javax.inject.Singleton;
11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.nio.charset.StandardCharsets;
14+
15+
/**
16+
* A service that setups up the CLAUDE.md file for a proejct.
17+
* It will download the latest version of the CLAUDE.md file from
18+
* https://github.com/shannah/jdeploy-claude/blob/main/CLAUDE.md, and append it to the project's
19+
* CLAUDE.md file if it exists, or create a new CLAUDE.md file if it does not exist.
20+
*/
21+
@Singleton
22+
public class SetupClaudeService {
23+
24+
private static final String CLAUDE_MD_URL = "https://raw.githubusercontent.com/shannah/jdeploy-claude/main/CLAUDE.md";
25+
26+
public void setup(File projectDirectory) throws IOException {
27+
if (projectDirectory == null || !projectDirectory.exists() || !projectDirectory.isDirectory()) {
28+
throw new IllegalArgumentException("Project directory must be a valid existing directory");
29+
}
30+
31+
File claudeFile = new File(projectDirectory, "CLAUDE.md");
32+
String claudeContent = downloadClaudeTemplate();
33+
34+
if (claudeFile.exists()) {
35+
String existingContent = FileUtils.readFileToString(claudeFile, StandardCharsets.UTF_8);
36+
if (!hasJDeploySection(existingContent)) {
37+
String combinedContent = existingContent + "\n\n" + claudeContent;
38+
FileUtils.writeStringToFile(claudeFile, combinedContent, StandardCharsets.UTF_8);
39+
}
40+
} else {
41+
FileUtils.writeStringToFile(claudeFile, claudeContent, StandardCharsets.UTF_8);
42+
}
43+
}
44+
45+
private boolean hasJDeploySection(String content) {
46+
String lowerContent = content.toLowerCase();
47+
return lowerContent.contains("Claude Instructions for jDeploy Setup".toLowerCase());
48+
}
49+
50+
private String downloadClaudeTemplate() throws IOException {
51+
CloseableHttpClient httpClient = HttpClients.createDefault();
52+
53+
try {
54+
HttpGet getRequest = new HttpGet(CLAUDE_MD_URL);
55+
getRequest.setHeader("Accept", "text/plain");
56+
57+
try (CloseableHttpResponse response = httpClient.execute(getRequest)) {
58+
int statusCode = response.getStatusLine().getStatusCode();
59+
if (statusCode == 200) {
60+
return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
61+
} else {
62+
throw new IOException("Failed to download CLAUDE.md template. HTTP status: " + statusCode);
63+
}
64+
}
65+
} finally {
66+
httpClient.close();
67+
}
68+
}
69+
}

cli/src/main/java/ca/weblite/jdeploy/factories/PublishTargetFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
public class PublishTargetFactory {
1111
private static final String GITHUB_URL = "https://github.com/";
1212
public PublishTargetInterface createWithUrlAndName(String url, String name) {
13+
return createWithUrlAndName(url, name, false);
14+
}
15+
16+
public PublishTargetInterface createWithUrlAndName(String url, String name, boolean isDefault) {
1317
return url.startsWith(GITHUB_URL)
14-
? new PublishTarget(getName(url, name), PublishTargetType.GITHUB, url)
15-
: new PublishTarget(getName(url, name), PublishTargetType.NPM, url);
18+
? new PublishTarget(getName(url, name), PublishTargetType.GITHUB, url, isDefault)
19+
: new PublishTarget(getName(url, name), PublishTargetType.NPM, url, isDefault);
1620
}
1721

1822
private String getName(String url, String name) {

0 commit comments

Comments
 (0)