Skip to content

Commit 160cf3e

Browse files
authored
GH workflow: For forks pull_requests use base Maven repo (#5)
1 parent 0da38da commit 160cf3e

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

.github/workflows/maven.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,22 @@ env:
1818
ACTIONS_STEP_DEBUG: true
1919

2020
jobs:
21-
build:
21+
fork_setup:
22+
runs-on: ubuntu-latest
23+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true }}
24+
outputs:
25+
base_repo: ${{ steps.base_repo.outputs.name }}
26+
is_fork: ${{ steps.is_fork.outputs.is_fork }}
27+
28+
steps:
29+
- id: base_repo
30+
run: echo "name=${{github.event.pull_request.base.repo.full_name}}" >> "$GITHUB_OUTPUT"
31+
- id: is_fork
32+
run: echo "is_fork=true" >> "$GITHUB_OUTPUT"
2233

34+
build:
2335
runs-on: ubuntu-latest
36+
needs: fork_setup
2437

2538
steps:
2639
- uses: actions/checkout@v4
@@ -34,9 +47,16 @@ jobs:
3447
cache: maven
3548

3649
- name: Build with Maven
37-
run: mvn -B package --file pom.xml
50+
run: |
51+
echo "Debug env vars: is_fork=$IS_FORK base_repo=$BASE_REPO MAVEN_REPO=$MAVEN_REPO"
52+
mvn help:active-profiles
53+
echo "Using Maven repo=$(mvn help:evaluate -Dexpression=github_ci.maven_repo -q -DforceStdout)"
54+
mvn -B package --file pom.xml
3855
env:
3956
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password
57+
IS_FORK: ${{needs.fork_setup.outputs.is_fork}}
58+
BASE_REPO: ${{needs.fork_setup.outputs.base_repo}}
59+
4060

4161

4262
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ Other CDOC2 repositories:
160160
## Preconditions for building
161161
* Java 17
162162
* Maven 3.8.x
163-
* Docker available and running (required for running tests, use `-Dmaven.test.skip=true` to skip)
164163

165164
## Maven dependencies
166165

@@ -202,8 +201,18 @@ CDOC2 has been tested with JDK 17 and Maven 3.8.8
202201
mvn clean install
203202
```
204203

204+
### GitHub workflow build
205+
206+
Maven build is executed for GH event `pull_request` an and `push` to 'master'.
207+
208+
GH build workflow configures Maven repository automatically. For fork based pull_requests
209+
Maven repo value will be set to `github.event.pull_request.base.repo.full_name`. It can be overwritten
210+
by [defining repository variable](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/variables#creating-configuration-variables-for-a-repository)
211+
`MAVEN_REPO`
212+
213+
205214
## Testing
206-
By default tests that require smart-card are excluded from running. To execute all tests enable allTests maven profile
215+
By default, tests that require smart-card are excluded from running. To execute all tests enable allTests maven profile
207216
```
208217
mvn -PallTests test
209218
```

pom.xml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,49 @@
8585
</build>
8686
</profile>
8787

88+
<profile>
89+
<id>github_ci_fork</id>
90+
<!-- for forks use base maven repo "open-eid/cdoc2-java-ref-impl" -->
91+
<activation>
92+
<property>
93+
<!-- defined by maven.yml for forks only -->
94+
<name>env.BASE_REPO</name>
95+
</property>
96+
</activation>
97+
<properties>
98+
<github_ci.maven_repo>https://maven.pkg.github.com/${env.BASE_REPO}</github_ci.maven_repo>
99+
</properties>
100+
</profile>
101+
102+
<profile>
103+
<id>github_ci_not_fork_or_not_pull_request</id>
104+
<activation>
105+
<property>
106+
<!-- set by maven.yml for forks only -->
107+
<name>env.IS_FORK</name>
108+
<!-- "is_fork" is not defined, or is defined with a value which is not "true". -->
109+
<value>!true</value>
110+
</property>
111+
</activation>
112+
<properties>
113+
<!--suppress UnresolvedMavenProperty -->
114+
<github_ci.maven_repo>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</github_ci.maven_repo>
115+
</properties>
116+
</profile>
117+
118+
<profile>
119+
<id>overwrite "github_ci.maven_repo" from env var "MAVEN_REPO"</id>
120+
<activation>
121+
<property>
122+
<name>env.MAVEN_REPO</name>
123+
</property>
124+
</activation>
125+
<properties>
126+
<github_ci.maven_repo>https://maven.pkg.github.com/${env.MAVEN_REPO}</github_ci.maven_repo>
127+
</properties>
128+
</profile>
129+
130+
88131
<profile>
89132
<!-- activate github profile when run by github actions -->
90133
<id>github_ci</id>
@@ -103,7 +146,7 @@
103146
<!-- Although GITHUB_REPOSITORY contains repo, all organization packages are indexed there -->
104147
<!-- https://stackoverflow.com/questions/63041402/github-packages-single-maven-repository-for-github-organization -->
105148
<!--suppress UnresolvedMavenProperty -->
106-
<url>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</url>
149+
<url>${github_ci.maven_repo}</url>
107150
</repository>
108151

109152
</repositories>

0 commit comments

Comments
 (0)