Skip to content

Commit d46ada2

Browse files
ci(check-deployed-package): add workflow and Docker auth script
1 parent 620991c commit d46ada2

File tree

7 files changed

+135
-25
lines changed

7 files changed

+135
-25
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Check deployed package
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- 'feat/package-auto-check-script'
9+
pull_request:
10+
branches:
11+
- main
12+
- 'feat/package-auto-check-script'
13+
14+
jobs:
15+
check-deployed-package:
16+
name: Check deployed package
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: read
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Make run script executable
27+
run: chmod +x check-deployed-package/run.sh
28+
29+
- name: Verify environment variables
30+
run: |
31+
echo "GITHUB_ACTOR: ${{ github.actor }}"
32+
echo "Has GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN != '' }}"
33+
echo "Has LOGDASH_API_KEY: ${{ secrets.LOGDASH_API_KEY != '' }}"
34+
35+
- name: Run LogDash demo
36+
env:
37+
LOGDASH_API_KEY: ${{ secrets.LOGDASH_API_KEY }}
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
GITHUB_ACTOR: ${{ github.actor }}
40+
run: ./check-deployed-package/run.sh

check-deployed-package/Check.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ public static void main(String[] args) {
3838
int seedValue = Integer.parseInt(metricsSeed);
3939
metrics.set("users", seedValue);
4040
metrics.mutate("users", 1);
41-
42-
// Wait to ensure data is sent
43-
try {
44-
Thread.sleep(2000);
45-
} catch (InterruptedException e) {
46-
Thread.currentThread().interrupt();
47-
}
4841
}
4942
}
5043

check-deployed-package/Dockerfile

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
FROM eclipse-temurin:17-jdk
22

3+
ARG GITHUB_TOKEN
4+
ARG GITHUB_ACTOR
5+
36
WORKDIR /app
47

58
# Install Maven
69
RUN apt-get update && apt-get install -y maven && rm -rf /var/lib/apt/lists/*
710

8-
# Copy pom.xml and source files
11+
# Set environment variables for Maven authentication
12+
ENV GITHUB_TOKEN=${GITHUB_TOKEN}
13+
ENV GITHUB_ACTOR=${GITHUB_ACTOR}
14+
15+
# Copy Maven settings with GitHub authentication
16+
COPY check-deployed-package/settings.xml /root/.m2/settings.xml
17+
18+
# Copy project files
919
COPY check-deployed-package/pom.xml .
1020
COPY check-deployed-package/Check.java src/main/java/com/logdash/check/Check.java
1121

1222
# Download dependencies and compile
13-
RUN mvn compile
23+
RUN mvn dependency:resolve compile -B --no-transfer-progress \
24+
-Dgithub.username=${GITHUB_ACTOR} \
25+
-Dgithub.password=${GITHUB_TOKEN}
26+
27+
# Add environment variable validation
28+
ENV LOGDASH_API_KEY=""
29+
ENV LOGS_SEED=""
30+
ENV METRICS_SEED=""
1431

15-
CMD ["mvn", "exec:java"]
32+
# Run the application with environment validation
33+
CMD if [ -z "$LOGDASH_API_KEY" ]; then \
34+
echo "Error: LOGDASH_API_KEY environment variable is required"; \
35+
exit 1; \
36+
fi; \
37+
mvn exec:java -B --no-transfer-progress

check-deployed-package/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Use command below to test if the published SDK works:
55
```
66
LOGDASH_API_KEY=<your-api-key> ./check-deployed-package/run.sh
77
```
8+

check-deployed-package/pom.xml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5-
https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
63
<modelVersion>4.0.0</modelVersion>
74
<groupId>com.logdash</groupId>
85
<artifactId>check</artifactId>
96
<version>1.0.0</version>
7+
108
<properties>
119
<maven.compiler.source>17</maven.compiler.source>
1210
<maven.compiler.target>17</maven.compiler.target>
1311
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1412
</properties>
15-
16-
<repositories>
17-
<repository>
18-
<id>github</id>
19-
<name>GitHub Packages</name>
20-
<url>https://maven.pkg.github.com/logdash-io/java-sdk</url>
21-
</repository>
22-
</repositories>
23-
13+
2414
<dependencies>
2515
<dependency>
2616
<groupId>io.logdash</groupId>
2717
<artifactId>logdash</artifactId>
2818
<version>0.1.0</version>
2919
</dependency>
3020
</dependencies>
21+
22+
<repositories>
23+
<repository>
24+
<id>github</id>
25+
<name>GitHub Packages</name>
26+
<url>https://maven.pkg.github.com/logdash-io/java-sdk</url>
27+
<releases>
28+
<enabled>true</enabled>
29+
</releases>
30+
<snapshots>
31+
<enabled>true</enabled>
32+
</snapshots>
33+
</repository>
34+
</repositories>
35+
3136
<build>
3237
<plugins>
3338
<plugin>
@@ -45,8 +50,11 @@
4550
<version>3.1.0</version>
4651
<configuration>
4752
<mainClass>com.logdash.check.Check</mainClass>
53+
<options>
54+
<option>-Dfile.encoding=UTF-8</option>
55+
</options>
4856
</configuration>
4957
</plugin>
5058
</plugins>
5159
</build>
52-
</project>
60+
</project>

check-deployed-package/run.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ METRICS_SEED=$(awk 'BEGIN{srand(); print int(rand()*1000000)+1}')
1010
echo "Generated metrics seed: $METRICS_SEED"
1111

1212
echo "Building LogDash Java demo Docker image (using published package)..."
13-
docker build --no-cache -t logdash-java-demo -f check-deployed-package/Dockerfile .
13+
docker build --no-cache \
14+
--build-arg GITHUB_TOKEN="${GITHUB_TOKEN}" \
15+
--build-arg GITHUB_ACTOR="${GITHUB_ACTOR}" \
16+
-t logdash-java-demo \
17+
-f check-deployed-package/Dockerfile .
1418

1519
echo
1620
echo "Running LogDash Java demo..."

check-deployed-package/settings.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
5+
https://maven.apache.org/xsd/settings-1.0.0.xsd">
6+
7+
<servers>
8+
<server>
9+
<id>github</id>
10+
<username>${env.GITHUB_ACTOR}</username>
11+
<password>${env.GITHUB_TOKEN}</password>
12+
</server>
13+
</servers>
14+
15+
<profiles>
16+
<profile>
17+
<id>github-auth</id>
18+
<activation>
19+
<activeByDefault>true</activeByDefault>
20+
</activation>
21+
<repositories>
22+
<repository>
23+
<id>github</id>
24+
<name>GitHub Packages</name>
25+
<url>https://maven.pkg.github.com/logdash-io/java-sdk</url>
26+
<releases>
27+
<enabled>true</enabled>
28+
<updatePolicy>daily</updatePolicy>
29+
</releases>
30+
<snapshots>
31+
<enabled>true</enabled>
32+
<updatePolicy>always</updatePolicy>
33+
</snapshots>
34+
</repository>
35+
</repositories>
36+
</profile>
37+
</profiles>
38+
39+
<activeProfiles>
40+
<activeProfile>github-auth</activeProfile>
41+
</activeProfiles>
42+
</settings>

0 commit comments

Comments
 (0)