Skip to content

Commit

Permalink
RM-3158: support building from fork PR by using base maven repo (#3)
Browse files Browse the repository at this point in the history
* RM-3158: support building from fork PR by using github base maven repo
  • Loading branch information
jann0k committed Aug 16, 2024
1 parent 6da4701 commit 144884f
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 18 deletions.
49 changes: 34 additions & 15 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,44 @@ env:
ACTIONS_STEP_DEBUG: true

jobs:
build:
fork_setup:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true }}
outputs:
base_repo: ${{ steps.base_repo.outputs.name }}
is_fork: ${{ steps.is_fork.outputs.is_fork }}

steps:
- id: base_repo
run: echo "name=${{github.event.pull_request.base.repo.full_name}}" >> "$GITHUB_OUTPUT"
- id: is_fork
run: echo "is_fork=true" >> "$GITHUB_OUTPUT"

build:
runs-on: ubuntu-latest
needs: fork_setup

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4

with:
java-version: '17'
distribution: 'temurin'
overwrite-settings: true #generate settings.xml
cache: maven

- name: Build with Maven
run: mvn -B verify --file cdoc2-server/pom.xml
env:
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4

with:
java-version: '17'
distribution: 'temurin'
overwrite-settings: true #generate settings.xml
cache: maven

- name: Build with Maven
run: |
echo "Debug env vars: is_fork=$IS_FORK base_repo=$BASE_REPO MAVEN_REPO=$MAVEN_REPO"
mvn help:active-profiles --file cdoc2-server/
echo "Using Maven repo=$(mvn help:evaluate --file cdoc2-server/ -Dexpression=github_ci.maven_repo -q -DforceStdout)"
mvn -B verify --file cdoc2-server/pom.xml
env:
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password
IS_FORK: ${{needs.fork_setup.outputs.is_fork}}
BASE_REPO: ${{needs.fork_setup.outputs.base_repo}}


# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ cd cdoc2-server
mvn clean install
```

### GitHub workflow build

Maven build is executed for GH event `pull_request` an and `push` to 'master'.

GH build workflow configures Maven repository automatically. For fork based pull_requests
Maven repo value will be set to `github.event.pull_request.base.repo.full_name` (`open-eid/*`). It can be overwritten
by [defining repository variable](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/variables#creating-configuration-variables-for-a-repository)
`MAVEN_REPO`


### Running

See [admin-guide.md](cdoc2-server/admin-guide.md) for running

## Releasing and versioning
Expand Down
45 changes: 44 additions & 1 deletion cdoc2-server/get-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,49 @@
</properties>
</profile>

<profile>
<id>github_ci_fork</id>
<!-- for forks use base maven repo "open-eid/cdoc2-java-ref-impl" -->
<activation>
<property>
<!-- defined by maven.yml for forks only -->
<name>env.BASE_REPO</name>
</property>
</activation>
<properties>
<github_ci.maven_repo>https://maven.pkg.github.com/${env.BASE_REPO}</github_ci.maven_repo>
</properties>
</profile>

<profile>
<id>github_ci_not_fork_or_not_pull_request</id>
<activation>
<property>
<!-- set by maven.yml for forks only -->
<name>env.IS_FORK</name>
<!-- "is_fork" is not defined, or is defined with a value which is not "true". -->
<value>!true</value>
</property>
</activation>
<properties>
<!--suppress UnresolvedMavenProperty -->
<github_ci.maven_repo>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</github_ci.maven_repo>
</properties>
</profile>

<profile>
<id>overwrite "github_ci.maven_repo" from env var "MAVEN_REPO"</id>
<activation>
<property>
<name>env.MAVEN_REPO</name>
</property>
</activation>
<properties>
<github_ci.maven_repo>https://maven.pkg.github.com/${env.MAVEN_REPO}</github_ci.maven_repo>
</properties>
</profile>


<profile>
<!-- activate github profile when run by github actions -->
<id>github_ci</id>
Expand All @@ -70,7 +113,7 @@
<!-- Although GITHUB_REPOSITORY contains repo, all organization packages are indexed there -->
<!-- https://stackoverflow.com/questions/63041402/github-packages-single-maven-repository-for-github-organization -->
<!--suppress UnresolvedMavenProperty -->
<url>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</url>
<url>${github_ci.maven_repo}</url>
</repository>

</repositories>
Expand Down
45 changes: 44 additions & 1 deletion cdoc2-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,49 @@
</properties>

<profiles>
<profile>
<id>github_ci_fork</id>
<!-- for forks use base maven repo "open-eid/cdoc2-java-ref-impl" -->
<activation>
<property>
<!-- defined by maven.yml for forks only -->
<name>env.BASE_REPO</name>
</property>
</activation>
<properties>
<github_ci.maven_repo>https://maven.pkg.github.com/${env.BASE_REPO}</github_ci.maven_repo>
</properties>
</profile>

<profile>
<id>github_ci_not_fork_or_not_pull_request</id>
<activation>
<property>
<!-- set by maven.yml for forks only -->
<name>env.IS_FORK</name>
<!-- "is_fork" is not defined, or is defined with a value which is not "true". -->
<value>!true</value>
</property>
</activation>
<properties>
<!--suppress UnresolvedMavenProperty -->
<github_ci.maven_repo>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</github_ci.maven_repo>
</properties>
</profile>

<profile>
<id>overwrite "github_ci.maven_repo" from env var "MAVEN_REPO"</id>
<activation>
<property>
<name>env.MAVEN_REPO</name>
</property>
</activation>
<properties>
<github_ci.maven_repo>https://maven.pkg.github.com/${env.MAVEN_REPO}</github_ci.maven_repo>
</properties>
</profile>


<profile>
<!-- activate github profile when run by github actions -->
<id>github_ci</id>
Expand All @@ -63,7 +106,7 @@
<!-- Although GITHUB_REPOSITORY contains repo, all organization packages are indexed there -->
<!-- https://stackoverflow.com/questions/63041402/github-packages-single-maven-repository-for-github-organization -->
<!--suppress UnresolvedMavenProperty -->
<url>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</url>
<url>${github_ci.maven_repo}</url>
</repository>

</repositories>
Expand Down
45 changes: 44 additions & 1 deletion cdoc2-server/put-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,49 @@
</properties>
</profile>

<profile>
<id>github_ci_fork</id>
<!-- for forks use base maven repo "open-eid/cdoc2-java-ref-impl" -->
<activation>
<property>
<!-- defined by maven.yml for forks only -->
<name>env.BASE_REPO</name>
</property>
</activation>
<properties>
<github_ci.maven_repo>https://maven.pkg.github.com/${env.BASE_REPO}</github_ci.maven_repo>
</properties>
</profile>

<profile>
<id>github_ci_not_fork_or_not_pull_request</id>
<activation>
<property>
<!-- set by maven.yml for forks only -->
<name>env.IS_FORK</name>
<!-- "is_fork" is not defined, or is defined with a value which is not "true". -->
<value>!true</value>
</property>
</activation>
<properties>
<!--suppress UnresolvedMavenProperty -->
<github_ci.maven_repo>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</github_ci.maven_repo>
</properties>
</profile>

<profile>
<id>overwrite "github_ci.maven_repo" from env var "MAVEN_REPO"</id>
<activation>
<property>
<name>env.MAVEN_REPO</name>
</property>
</activation>
<properties>
<github_ci.maven_repo>https://maven.pkg.github.com/${env.MAVEN_REPO}</github_ci.maven_repo>
</properties>
</profile>


<profile>
<!-- activate github profile when run by github actions -->
<id>github_ci</id>
Expand All @@ -69,7 +112,7 @@
<!-- Although GITHUB_REPOSITORY contains repo, all organization packages are indexed there -->
<!-- https://stackoverflow.com/questions/63041402/github-packages-single-maven-repository-for-github-organization -->
<!--suppress UnresolvedMavenProperty -->
<url>https://maven.pkg.github.com/${env.GITHUB_REPOSITORY}</url>
<url>${github_ci.maven_repo}</url>
</repository>

</repositories>
Expand Down

0 comments on commit 144884f

Please sign in to comment.