-
Notifications
You must be signed in to change notification settings - Fork 5
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
AAE-10135: turn build-and-tag-maven GH reusable workflow into an acti… #105
Merged
atchertchian
merged 2 commits into
master
from
AAE-10135-change-maven-build-workflow-to-action
Oct 5, 2022
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 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,148 @@ | ||
name: Build and tag Maven project | ||
description: Build and tag Maven project | ||
inputs: | ||
java-version: | ||
description: The Java version to perform the build | ||
required: false | ||
default: '11' | ||
java-distribution: | ||
description: The Java distribution to perform the build | ||
required: false | ||
default: 'temurin' | ||
property-to-update: | ||
description: Property to update in addition to the version of the pom file | ||
required: false | ||
extra-maven-opts: | ||
description: Extra maven options for the build command line | ||
required: false | ||
maven-username: | ||
description: Nexus user name | ||
required: true | ||
maven-password: | ||
description: Nexus password | ||
required: true | ||
quay-username: | ||
description: Quay.io user name | ||
required: true | ||
quay-password: | ||
description: Quay.io password | ||
required: true | ||
docker-username: | ||
description: Docker.io user name | ||
required: true | ||
docker-password: | ||
description: Docker.io password | ||
required: true | ||
git-username: | ||
description: The username to commit on the git repository | ||
required: true | ||
|
||
outputs: | ||
version: | ||
description: "The version of the new tag created by this workflow" | ||
value: ${{ steps.update-pom-to-next-version.outputs.next-prerelease }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@a18c333f3f14249953dab3e186e5e21bf3390f1d | ||
with: | ||
java-version: ${{ inputs.java-version }} | ||
distribution: ${{ inputs.java-distribution }} | ||
cache: 'maven' | ||
|
||
- name: Update pom files to the new version | ||
id: update-pom-to-next-version | ||
if: github.event_name == 'push' | ||
uses: Alfresco/alfresco-build-tools/.github/actions/update-pom-to-next-pre-release@v1.16.0 | ||
with: | ||
property-to-update: ${{ inputs.property-to-update }} | ||
maven-cli-opts: --show-version --no-transfer-progress --settings settings.xml | ||
env: | ||
MAVEN_USERNAME: ${{ inputs.maven-username }} | ||
MAVEN_PASSWORD: ${{ inputs.maven-password }} | ||
|
||
- name: Set version env variable | ||
if: github.event_name == 'push' | ||
env: | ||
VERSION: ${{ steps.update-pom-to-next-version.outputs.next-prerelease }} | ||
shell: bash | ||
run: | | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
|
||
- name: Login to DockerHub Registry | ||
if: github.event_name == 'push' | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: docker.io | ||
username: ${{ inputs.docker-username }} | ||
password: ${{ inputs.docker-password }} | ||
|
||
- name: Login to Quay.io Docker Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: quay.io | ||
username: ${{ inputs.quay-username }} | ||
password: ${{ inputs.quay-password }} | ||
|
||
- name: Define Maven Command | ||
id: define_maven_command | ||
shell: bash | ||
run: | | ||
if [ $DO_PUSH == 'true' ] | ||
then | ||
echo "::set-output name=command::deploy" | ||
else | ||
echo "::set-output name=command::verify" | ||
fi | ||
env: | ||
DO_PUSH: ${{ github.event_name == 'push' }} | ||
|
||
- name: Build and Test with Maven (and maybe Deploy) | ||
shell: bash | ||
run: mvn ${{ steps.define_maven_command.outputs.command }} ${{ env.MAVEN_CLI_OPTS}} ${{ inputs.extra-maven-opts }} | ||
env: | ||
MAVEN_CLI_OPTS: --show-version --no-transfer-progress --settings settings.xml -Dlogging.root.level=off -Dspring.main.banner-mode=off -Ddocker.skip | ||
MAVEN_USERNAME: ${{ inputs.maven-username }} | ||
MAVEN_PASSWORD: ${{ inputs.maven-password }} | ||
|
||
- name: Echo Longest Tests run | ||
shell: bash | ||
run: find . -name TEST-*.xml -exec grep -h testcase {} \; | awk -F '"' '{printf("%s#%s() - %.3fms\n", $4, $2, $6); }' | sort -n -k 3 | tail -20 | ||
|
||
- name: Define Docker Push | ||
id: define_docker_push | ||
shell: bash | ||
run: | | ||
if [ $DO_PUSH == 'true' ] | ||
then | ||
echo "::set-output name=command::--push" | ||
fi | ||
env: | ||
DO_PUSH: ${{ github.event_name == 'push' }} | ||
|
||
- name: Docker Build (and maybe Push) | ||
shell: bash | ||
run: | | ||
TAG="${TAG:-$(echo ${GITHUB_HEAD_REF:-$GITHUB_REF_NAME} | sed -e 's/[^-_.[:alnum:]]/_/g')}" | ||
sh ./build-and-push-docker-images.sh | ||
env: | ||
PUSH_OPTION: ${{ steps.define_docker_push.outputs.command }} | ||
TAG: ${{env.VERSION}} | ||
|
||
- uses: Alfresco/alfresco-build-tools/.github/actions/git-commit-changes@v1.16.0 | ||
if: github.event_name == 'push' | ||
with: | ||
username: ${{ inputs.git-username }} | ||
add-options: -u | ||
commit-message: "release $VERSION" | ||
|
||
- name: Create and push tag | ||
if: github.event_name == 'push' | ||
shell: bash | ||
run: | | ||
git tag -a $VERSION -m "Release version $VERSION" | ||
git push origin $VERSION |
This file contains 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
This file contains 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.
maybe those could be optional since it depends on the packages you are building if they need to push to quay or docker or both
you could also skip docker-login steps depending on those inputs empty or not (otherwise they will fail)
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.
IIRC, we always need to login to Docker Hub, even when we are pushing images to quay.io, that's because some base images and images used by integration tests are hosted in Docker Hub and without login, we run out of quota to pull those images.
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.
yeah for your specific use case it's fine but I am always thinking if there is more room to make this action reusable in different contexts
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.
It makes sense to make it as reusable as possible, but I prefer to minimize the amount of work without anticipating too much. The risk is spending time adding logic that will never be used. We can always evolve the implementation to cover new scenarios when they are needed. Does it make sense?