-
Notifications
You must be signed in to change notification settings - Fork 3
[NCL-9648] Add gradle build action #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| name: Java CI with Gradle | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| java_version: | ||
| description: "The Java version to use to compile. Default: 17" | ||
| required: false | ||
| type: string | ||
| default: "17" | ||
| gradle_version: | ||
| description: "The Gradle version to use, or 'wrapper'. Default: wrapper" | ||
| required: false | ||
| type: string | ||
| default: "wrapper" | ||
| build_args: | ||
| description: "Args for gradle build" | ||
| required: true | ||
| type: string | ||
| fetch_all_commits: | ||
| description: "Whether to fetch all commits. Default: false" | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| pre_build_script: | ||
| description: "Optional script to run after checkout, before the build." | ||
| required: false | ||
| type: string | ||
| default: "" | ||
| upload_coverage: | ||
| description: "Whether to upload coverage to Codecov. Default: false" | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| coverage_files: | ||
| description: "Coverage report files to upload when 'upload_coverage' is true." | ||
| required: false | ||
| type: string | ||
| default: "" | ||
| upload_artifacts: | ||
| description: "Whether to upload artifacts and their metadata. Default: false" | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.java_version }}-${{ inputs.gradle_version }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| fetch-depth: ${{ inputs.fetch_all_commits == true && '0' || '1' }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Run pre-build script | ||
| if: inputs.pre_build_script != '' | ||
| shell: bash | ||
| env: | ||
| PRE_BUILD_SCRIPT: ${{ inputs.pre_build_script }} | ||
| run: bash -c "${PRE_BUILD_SCRIPT}" | ||
|
|
||
| - uses: project-ncl/shared-github-actions/.github/actions/gradle-build@8508c5b6bbd47f9528410b0f7de23231b09e86e1 # main | ||
| with: | ||
| java_version: ${{ inputs.java_version }} | ||
| gradle_version: ${{ inputs.gradle_version }} | ||
| build_args: ${{ inputs.build_args }} | ||
|
|
||
| - name: Codecov | ||
| if: inputs.upload_coverage | ||
| uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0 | ||
| with: | ||
| files: ${{ inputs.coverage_files }} | ||
| verbose: true | ||
|
|
||
| - name: Save PR metadata | ||
| if: inputs.upload_artifacts | ||
| env: | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| PR_SHA: ${{ github.event.pull_request.head.sha }} | ||
| run: | | ||
| mkdir -p pr-metadata | ||
| echo "$PR_NUMBER" > pr-metadata/pr-number | ||
| echo "$PR_SHA" > pr-metadata/pr-sha | ||
|
|
||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| if: inputs.upload_artifacts | ||
| with: | ||
| name: pr-build | ||
| path: | | ||
| . | ||
| !.git | ||
| !pr-metadata | ||
| retention-days: 1 | ||
|
|
||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| if: inputs.upload_artifacts | ||
| with: | ||
| name: pr-metadata | ||
| path: pr-metadata | ||
| retention-days: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| name: Build snapshot version and upload to Gradle Central | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| project_name: | ||
| # format: <organisation>/<project_name> | ||
| description: "The project name to run the job. Prevent forks to run snapshot job" | ||
| required: true | ||
| type: string | ||
| java_version: | ||
| description: "The Java version to use to compile. Default: 17" | ||
| required: false | ||
| type: string | ||
| default: "17" | ||
| fetch_all_commits: | ||
| description: "Whether to fetch all commits. Default: false" | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
|
|
||
| secrets: | ||
| SONATYPE_USERNAME: | ||
| required: true | ||
| SONATYPE_PASSWORD: | ||
| required: true | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| snapshot: | ||
| if: github.repository == inputs.project_name | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| fetch-depth: ${{ inputs.fetch_all_commits == true && '0' || '1' }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up JDK '${{ inputs.java_version }}' | ||
| uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 | ||
| with: | ||
| java-version: "${{ inputs.java_version }}" | ||
| distribution: "temurin" | ||
| cache: gradle | ||
| server-id: central-publisher # we use this in our pom.xml | ||
| server-username: MAVEN_USERNAME # env var name for username | ||
| server-password: MAVEN_PASSWORD # env var name for password | ||
|
|
||
| - name: Extract Project version | ||
| id: project-version | ||
| run: echo "version=$(awk -F "=" 'BEGIN{ORS=""} /version/{print $NF}' gradle.properties)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - uses: project-ncl/shared-github-actions/.github/actions/gradle-build@8508c5b6bbd47f9528410b0f7de23231b09e86e1 # main | ||
| if: ${{ endsWith(steps.project-version.outputs.version, '-SNAPSHOT') }} | ||
| with: | ||
| java_version: ${{ inputs.java_version }} | ||
| build_args: "build publishToCentral -x test -x funcTest" | ||
| env: | ||
| MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }} | ||
| MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing matching configuration from the maven-snapshot i.e. configuring server-id, server-username etc. I am wondering if that is why I needed that workaround or deleting the settings file and generating a new one below below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think after some experimentation its due to the fact that the settings.xml always ends up being generated and the settings loader plugin I was using attempts to decrypt it annoyingly. I'm seeing if I can remove that plugin and use a custom implementation which would simplify the work here (See project-ncl/gradle-manipulator#538 )