diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b2aa47d1..0921c0415 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: 'true' + fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v4 with: @@ -30,6 +31,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: 'true' + fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v4 with: @@ -61,6 +63,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: 'true' + fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v4 with: @@ -92,6 +95,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: 'true' + fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v4 with: @@ -141,20 +145,28 @@ jobs: check_name: Junit Tests - Summary files: '**/TEST-*.xml' + # The version is derived from git tags by the gradle git-versioning plugin (see CONTRIBUTING.md#release), + # so main publishes -SNAPSHOT and a vX.Y.Z tag publishes X.Y.Z. publishSnapshot: if: ${{ github.ref == 'refs/heads/main' }} needs: [test, slowTest, integrationTest] runs-on: ubuntu-latest + permissions: + contents: read + packages: write steps: - uses: actions/checkout@v4 + with: + # Full history, the gradle git-versioning plugin derives the version from tags. + fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: 17 cache: 'gradle' - - name: Publish release package - run: ./gradlew publish -x test -x slowTest -x integrationTest -Pinclude.documentation -PpublishToGithub -Pversion=$(cat VERSION)-SNAPSHOT + - name: Publish snapshot package + run: ./gradlew publish -x test -x slowTest -x integrationTest -Pinclude.documentation -PpublishToGithub env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -162,15 +174,28 @@ jobs: if: ${{ startsWith(github.ref, 'refs/tags/v') }} needs: [test, slowTest, integrationTest] runs-on: ubuntu-latest + permissions: + contents: read + packages: write steps: - uses: actions/checkout@v4 + with: + # Full history, the gradle git-versioning plugin derives the version from tags. + fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: 17 cache: 'gradle' - - name: Publish snapshot package - run: ./gradlew publish -x test -x slowTest -x integrationTest -Pinclude.documentation -PpublishToGithub -Pversion=$(cat VERSION) + - name: Check version matches tag + run: | + version=$(./gradlew -q printVersion | tail -1) + if [ "$version" != "${GITHUB_REF_NAME#v}" ]; then + echo "::error::Gradle version '$version' does not match tag '$GITHUB_REF_NAME'" + exit 1 + fi + - name: Publish release package + run: ./gradlew publish -x test -x slowTest -x integrationTest -Pinclude.documentation -PpublishToGithub env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 710696b84..000000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,256 +0,0 @@ -# -# Gitlab build file for GOR. -# - -include: - - project: wuxi-nextcode/sdev/gitlab-ci-scripts - file: /auto-ci-workflow/legacy.yml - -variables: - DOCKER_DRIVER: overlay2 - JAVA_BUILDER_IMAGE: registry.gitlab.com/wuxi-nextcode/sdev/build-images/java-17:latest - GIT_SUBMODULE_STRATEGY: none - GIT_DEPTH: 2 - GRADLE_USER_HOME: "cache/" - GRADLE_OPTS: "-Dorg.gradle.daemon=false" - SECURITY_SCAN: "false" - SKIP_ECR: 'yes' # Skip the push to ECR step - # Vars needed for the Genuity Auto-CI - #RELEASABLE_BRANCH: 584-oci-cloud-gor-driver - RELEASABLE_BRANCH: master # Optional (master is the default). If this matches the current branch, the built image will be releasable with a semver tag. - - -.publish-snapshot-version-from-commit: - before_script: - - export VERSION="$(cat VERSION)-SNAPSHOT" - -# Triggers running on branch that should be releasable (by tagging later), must start with v so we don't pick merge requests. - -.on-releasable-or-release-branch-only: - rules: - - if: $CI_COMMIT_REF_NAME == $RELEASABLE_BRANCH - - if: $CI_COMMIT_REF_NAME =~ /^release\/v(0|[1-9]\d*)\.(0|[1-9]\d*)$/ - - -stages: - - build - - test - - publish - - promote - - release - - deploy - - -before_script: - - export GRADLE_USER_HOME=`pwd`/.gradle - - -.build_with_cache: - extends: .on-branches - image: "$JAVA_BUILDER_IMAGE" - tags: - - gitlab-build-01 - variables: - # Vars for build resources - KUBERNETES_CPU_REQUEST: 2 - KUBERNETES_CPU_LIMIT: 6 - KUBERNETES_MEMORY_REQUEST: 2Gi - KUBERNETES_MEMORY_LIMIT: 6Gi - cache: - #key: "$CI_COMMIT_REF_NAME" # Cache per branch. - key: - files: - - gradle/wrapper/gradle-wrapper.properties # Cache per version of Gradle wrapper. - - policy: pull - paths: - - cache/caches/ - - cache/notifications/ - - cache/wrapper/ - - -build: - extends: .build_with_cache - image: "$JAVA_BUILDER_IMAGE" - stage: build - variables: - GRADLE_OPTS: "-Dorg.gradle.daemon=false" - script: ./gradlew classes - cache: - policy: pull-push - artifacts: - paths: - - "**/build/libs/*.jar" - -.test: - extends: .build_with_cache - stage: test - variables: - GIT_SUBMODULE_STRATEGY: recursive - GRADLE_OPTS: "-Dorg.gradle.daemon=false" - before_script: - - ln -s ${INTEGRATION_TESTS_SECRETS_ENV} tests/config/secrets.env - artifacts: - reports: - junit: - - "*/*/*/*/TEST-*.xml" - - "*/*/*/*/*/TEST-*.xml" - # Seems like ** does not work properly (even though it is used in the Gitlab docutmentation) - #- "**/build/test-results/test/**/TEST-*.xml" - -# Is a litle bit faster, but does not publish test results! -build_test: - rules: - - when: never - extends: - - .build_with_cache -# - .test - stage: build - variables: - GIT_SUBMODULE_STRATEGY: recursive - GRADLE_OPTS: "-Dorg.gradle.daemon=false" - before_script: - - ln -s ${INTEGRATION_TESTS_SECRETS_ENV} tests/config/secrets.env - script: ./gradlew --continue test slowTest integrationTest - cache: - policy: pull-push - artifacts: - paths: - - "**/build/libs/*.jar" - reports: - junit: - - "*/*/*/*/TEST-*.xml" - - "*/*/*/*/*/TEST-*.xml" - # Seems like ** does not work properly (even though it is used in the Gitlab documentation) - #- "**/build/test-results/test/**/TEST-*.xml" - - -unittest: - extends: .test - script: ./gradlew --continue test - - -slowtest: - extends: .test - script: ./gradlew --continue slowTest - - -integrationtest: - extends: .test - script: ./gradlew --continue integrationTest - - -testcoverage: - rules: - - when: never - extends: - #- .on-releasable-or-release-branch-only - - .test - script: ./gradlew --continue jacocoTestReport - artifacts: - reports: - coverage_report: - coverage_format: cobertura - # gorscripts is top level and should include everything else. - path: "gorscripts/build/reports/jacoco/testCodeCoverageReport/cobertura.xml" - - -# This code quality block is needed to work around https://gitlab.com/gitlab-org/gitlab/issues/12274 -code_quality: - extends: - - .on-releasable-or-release-branch-only - stage: test - tags: - - gitlab-build-01 - variables: - KUBERNETES_CPU_REQUEST: 2 - KUBERNETES_CPU_LIMIT: 6 - KUBERNETES_MEMORY_REQUEST: 3Gi - KUBERNETES_MEMORY_LIMIT: 6Gi - TIMEOUT_SECONDS: "1200" - #CODECLIMATE_DEBUG: "1" - ENGINE_MEMORY_LIMIT_BYTES: "3221223823" - artifacts: - reports: - codequality: gl-code-quality-report.json - paths: [gl-code-quality-report.json] - expire_in: 1 week - - -dependency_scanning: - stage: test - tags: - - gitlab-build-01 - variables: - KUBERNETES_CPU_REQUEST: 4 - KUBERNETES_CPU_LIMIT: 6 - KUBERNETES_MEMORY_REQUEST: 2Gi - KUBERNETES_MEMORY_LIMIT: 6Gi - DS_DEFAULT_ANALYZERS: "gemnasium-maven" - # There is no need to run tests or generate sphinx documentation for license management - # analysis, however, the license management plugin calls the build task so we have to manually - # disable tests and documentation generation. - SECURE_LOG_LEVEL: "debug" - GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dskip.tests=true" - artifacts: - paths: [gl-dependency-scanning-report.json] - - -spotbugs-sast: - variables: - KUBERNETES_CPU_REQUEST: 4 - KUBERNETES_CPU_LIMIT: 6 - KUBERNETES_MEMORY_REQUEST: 2Gi - KUBERNETES_MEMORY_LIMIT: 6Gi - GRADLE_PATH: "$CI_PROJECT_DIR/gradlew" - SAST_JAVA_VERSION: "17" - JAVA_OPTS: "-Xmx4G" - SECURE_LOG_LEVEL: "debug" - GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.caching=true -Dskip.tests=true" - rules: - - if: '$SECURITY_SCAN == "true"' - - -.publish-base: - extends: - - .build_with_cache - stage: publish - script: - - ./gradlew publish -x test -x slowTest -x integrationTest -Pinclude.documentation -Pversion=${VERSION} - -publish-snapshot: - extends: - - .publish-base - - .on-releasable-branch - - .publish-snapshot-version-from-commit - -publish: - extends: - - .publish-base - - .on-semver-tag - -# Disable default tasks that should not be triggered. - -container_scanning: - rules: - - when: never - -promote-container: - rules: - - when: never - -tag-container: - rules: - - when: never - -push-snapshot-to-dockerhub: - rules: - - when: never - -push-feature-branch-docker-to-dockerhub: - rules: - - when: never - -push-version-to-dockerhub: - rules: - - when: never diff --git a/CLAUDE.md b/CLAUDE.md index be9d47f32..271bcf0cb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -157,8 +157,8 @@ make publish-local ## Versioning -- Version stored in `VERSION` file at repo root +- No version file: version is derived from `vX.Y.Z` git tags by the gradle git-versioning plugin (`build.gradle`) - Semantic versioning: `..` -- Development versions use `-SNAPSHOT` suffix -- Releases: `make release-milestone-from-master MILESTONE=X.Y.Z` +- Tag checkout builds `X.Y.Z`, anything else builds `-SNAPSHOT`; print with `make gitversion`, override with `-Pversion=...` +- Releases: create a `vX.Y.Z` release/tag on `main` on GitHub, see CONTRIBUTING.md#release - Dependency versions managed in `versions.properties` (refreshVersions plugin); update with `./gradlew refreshVersions` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1d2a707b8..df0aaeaee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,8 +2,6 @@ For developers of GOR, people who want to contribute to the GOR codebase or documentation, or people who want to install from source and make local changes to their copy of GOR. -For this to work you'll need to have merge rights to master otherwise te push from release script will fail. - ## Reporting an Issue TBD @@ -12,104 +10,40 @@ TBD ## Release -This section is for developers of GOR and describes how releases are created from our Gitlab environment. - -The steps are as follows: - -1. Review the operation dashboard. -2. Update the relevant milestone. -3. Create the release. -4. Close the milestone. -5. Notify Software Development -6. Create a release on GitHub (optional) -7. Create a release of Gor Services (optional) - -Each one is described in more detail below. +This section is for developers of GOR and describes how releases are created on [GitHub](https://github.com/gorpipe/gor). -Notes on versioning: -1. GOR uses semantic versioning, with `..` format. -2. We use `-SNAPSHOT` postfix to indicate development version. -3. We update the version at the time of release so for example `10.2.3-SNAPSHOT` is a development version on top on released version `10.2.3`. Next version will be `10.2.4`,`10.3.0` or `11.0.0` +### Versioning -### Reviewing Operations Dashboard +We use [semantic versioning](https://semver.org), `..`, and release tags are `vX.Y.Z`. -Before creating a GOR release, make sure that there are no issues in the Operations Dashboards related to GOR: https://gitlab.com/-/operations +There is no version file, the version is derived from git tags by the gradle +[git-versioning plugin](https://github.com/qoomon/gradle-git-versioning-plugin) (see `build.gradle`): -### Updating the Milestone +- A commit tagged `vX.Y.Z` builds version `X.Y.Z`. +- Any other commit builds `-SNAPSHOT`, e.g. `5.14.0-SNAPSHOT` is a development version on top of + the released `5.14.0`. Snapshots from `main` are published to GitHub Packages. +- `make gitversion` (or `./gradlew -q printVersion`) prints the current version, `-Pversion=...` overrides it. +- A shallow clone without tags falls back to `0.0.0-SNAPSHOT`, so CI checkouts that run gradle use `fetch-depth: 0`. -After last release there should be milestone created for this release under [>Issues>Milestones](https://gitlab.com/wuxi-nextcode/wxnc-gor/gor/-/milestones). +Pick the next version from the changes since the last release: -Review all merge requests since the last release and make sure that they along with their underlying issues are tagged with the milestone for the upcoming release. - -Also, review all issues with merge requests that have been merged and make sure that they are tagged with the appropriate milestone ([Closed issues without milestone](https://gitlab.com/wuxi-nextcode/wxnc-gor/gor/-/issues/?sort=created_date&state=closed&milestone_title=None&first_page_size=20)) - -Make sure that the issues are bulked edited and make sure that the status is Closed, tagged with **Status:Done** and milestone set to the current milestone. After saving goto the milestone and make sure that all issues are tagged with either **Feature Request** or **Bug**. If not then edit the issue to include the correct tag as this is reflected in the release notes. +- Only fixes bump PATCH, e.g. `5.14.0` -> `5.14.1`. +- New features bump MINOR, e.g. `5.14.0` -> `5.15.0`. +- Breaking changes bump MAJOR, e.g. `5.14.0` -> `6.0.0`. ### Creating a Release -When creating the actual release we can either release directly from master (now preferred) or create release branch and release from there. -Using a release branch (with dependency locks) is preferred only if we expect that we will be creating patches on very old releases. - -#### Create Release Directly from Master - Now Preferred - -Make sure have an open milestone with all the issues, then call: - -`make release-milestone-from-master MILESTONE=1.1.1` - -this will update the version, create release notes, create the release by tagging, and close the milestone. - -In case of an error you need to roll back the release. - 1. Goto the [tags](https://gitlab.com/wuxi-nextcode/wxnc-gor/gor/-/tags) and remove the tag with the current version - 2. Goto the [milestone](https://gitlab.com/wuxi-nextcode/wxnc-gor/gor/-/milestones?sort=due_date_desc&state=closed) and reopen the curent milestone. - 3. Fix any issue related to error - 4. Rerun the make script - -This can also be done manually. - -#### Create a Patch Directly from Master - Now Preferred - -Exactly like creating a release except only the patch number should change when updating the version number. - -#### Create Release From a Release Branch - Older -Open a shell within in the folder where the GOR repository lies and enter the following with the release version correctly updated: +1. Make sure `main` contains everything that should go into the release and that the CI build on `main` is green. +2. Under [Releases](https://github.com/gorpipe/gor/releases), press **Draft a new release**. +3. Create a new tag `vX.Y.Z` on `main` (the tag must be strictly `vX.Y.Z`, other tags are ignored by the versioning) + and use it as the release title. +4. Press **Generate release notes**, review them and press **Publish release**. +5. The tag push triggers the CI build (`.github/workflows/build.yml`), which runs all tests, checks that the gradle + version matches the tag and publishes the release to GitHub Packages. -1. `make create-release-branch BRANCH_VERSION=1.1` -2. `make update-master-version NEW_VERSION=1.2.0-SNAPSHOT` This creates a branch with the changes thats need to be merged manually!! -3. Open a browser and [create a tag on the release branch](https://gitlab.com/wuxi-nextcode/wxnc-gor/gor/-/tags), put the release notes in the Release Notes field. Alternatively we can tag using `make release-from-release BRANCH_VERSION=1.1`. - -#### Create Patch From Release Branch - Older - -For patches we have two cases: -- We will usually have the change made to master and then cherry picked to the release branches. In this case we will have only the pull request to master, but we still have to mark the issue with all the releases the fix went into. -- Sometimes we must create pull requests for the patch versions too and in that case the issue will have multiple branches and pull request. - -After updating the release branch, open a shell within in the folder where the GOR repository lies and enter the following with the release version correctly updated: - -1. `make update-release-version BRANCH_VERSION=1.1 NEW_VERSION=1.1.1` -2. Open a browser and [create a tag on the release branch](https://gitlab.com/wuxi-nextcode/wxnc-gor/gor/-/tags), put the release notes in the Release Notes field. Alternatively we can tag using `make release-from-release BRANCH_VERSION=1.1`. - -#### Closing Out Milestone - Older - -If creating the release was successful, update the milestone by adding a description, setting Due Date to today and press the "Close milestone" button. Then create a new milestone for the next release. - -### Notify Software Development - -Notify software deveplopment that a release has been creating by posting on the #sdev that the release has been created with the features listed under the milestone. Include links to the milestone and the GitHub release. - -### Creating a Release on GitHub - -The release branch and tag for the release should automatically be mirrored to the GOR repository on [GitHub](https://github.com/gorpipe/gor). A release on GitHub is created going through the following steps: - -- Under [Releases](https://github.com/gorpipe/gor/releases), press button "Draft a new release" -- Select the tag for the new release and set that as the release title as well -- In the description, use the same description as used in the milestone in GitLab -- For the binaries go into [Package Registry](https://gitlab.com/wuxi-nextcode/wxnc-gor/gor/-/packages) and under org/gorpipe/gor-tools for the release download file `gor-scripts-1.1.0-dist.zip` -- Attach file `gor-scripts-1.1.0-dist.zip` by dragging it to the "Attach binaries" box -- After uplading the binaries is complete, press the "Publish release" button - -Make sure to update the release version as appropriate. +If the tag build fails, fix it on `main` and create a new release (the next patch version). ### Create a Release of GOR Services -To update our customer environments, we will need to create a new release of GOR Services including this GOR release. That process is documented in the [GOR Services repo](https://gitlab.com/wuxi-nextcode/wxnc-gor/gor-services/-/blob/master/CONTRIBUTING.md). - +To update our customer environments, we will need to create a new release of GOR Services including this GOR release. +That process is documented in the [GOR Services repo](https://github.com/GeneDx/gdb-gor-services/blob/main/CONTRIBUTING.md#release). diff --git a/Makefile b/Makefile index eb3638b24..5ff00ca28 100644 --- a/Makefile +++ b/Makefile @@ -2,15 +2,13 @@ SHORT_NAME = gor BRANCH = $$(git rev-parse --abbrev-ref HEAD) COMMIT_HASH = $$(git rev-parse --short HEAD) -CURRENT_VERSION = $$(cat VERSION) -CURRENT_TAG_VERSION = "v${CURRENT_VERSION}" help: ## This help. @grep -E '^[a-zA-Z0-9_-]+:.*?#*.*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?#+"}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' # # Common build targets - just the most common gradle targets. -# +# clean: ## Clean the build env. ./gradlew clean @@ -25,133 +23,36 @@ compile-all-with-warnings: ## Compile code and tests. ./gradlew --rerun-tasks --console=plain --warning-mode all clean compileJava compileTestJava build-doc: ## Build documentation - ./gradlew :documentation:publishToMavenLocal -Pinclude.documentation -Pversion=$(CURRENT_VERSION)-SNAPSHOT + ./gradlew :documentation:publishToMavenLocal -Pinclude.documentation build-doc-os-aarch: ## Build documentation on osx using aarch - ./gradlew :documentation:publishToMavenLocal -Pinclude.documentation -Psphinx.binaryUrl="https://github.com/trustin/sphinx-binary/releases/download/v0.8.1/sphinx.osx-x86_64" -Pversion=$(CURRENT_VERSION)-SNAPSHOT + ./gradlew :documentation:publishToMavenLocal -Pinclude.documentation -Psphinx.binaryUrl="https://github.com/trustin/sphinx-binary/releases/download/v0.8.1/sphinx.osx-x86_64" # # Local testinga # publish-local: ## Publish libraries locally (mavenLocal), then compile services with -PuseMavenLocal - ./gradlew -Pversion=$(CURRENT_VERSION)-SNAPSHOT publishToMavenLocal -x documentation:publishToMavenLocal + ./gradlew publishToMavenLocal -x documentation:publishToMavenLocal publish-maven-central: ## Publish to maven central - ./gradlew -Pversion=$(CURRENT_VERSION)-SNAPSHOT -PpublishToMavenCentral publish + ./gradlew -PpublishToMavenCentral publish docker-build: build ## Build all docker images docker build . # -# Git targets +# Git helpers. Releases are created by tagging on GitHub, see CONTRIBUTING.md#release. # - -update-master: ## Update master and its submodules - git checkout master - git pull - git submodule update --init --recursive - update-branch: ## Update the current branch git pull git submodule update --init --recursive +gitversion: ## Get current version (derived from git tags) + @./gradlew -q printVersion | tail -1 -# -# Release from master. -# - -release-milestone-from-master: ## Release from master based on milestone (MILESTONE must be passed in) - @buildSrc/src/main/scripts/release_milestone_from_master.sh 17033400 ${MILESTONE} - - -release-from-master: ## Release from master (VERSION must be passed in). DEPRECATED: Use release-milestone-from-master instead. - @if [ -z "${VERSION}" ]; then { echo "ERROR: VERSION should be set! Exiting..."; exit 1; }; fi - - git checkout master - git pull - - echo "${VERSION}" > VERSION - git add VERSION - - # Commit and push to the branch - git commit -m "Updated version to ${VERSION}" - git push - - git tag -a "v${VERSION}" -m "Releasing GOR v${VERSION}" - git push origin "v${VERSION}" - -# -# Release from release branch. -# - -update-master-version: update-master ## Update version on the master branch, assumes NEW_VERSION is passed in. DEPRECATED: Use release-milestone-from-master instead. - @if [ -z "${NEW_VERSION}" ]; then { echo "ERROR: NEW_VERSION should be set! Exiting..."; exit 1; }; fi - - # Update version on master - git checkout -b "Update_master_version_to_${NEW_VERSION}" - - # Update the version numbers - echo "${NEW_VERSION}" > VERSION - git add VERSION - - # Commit and push to the branch - git commit -m "Updated version to ${NEW_VERSION} on master." - git push -u origin "Update_master_version_to_${NEW_VERSION}" - -# Create a release branch with library locks and update version info. -create-release-branch: update-master ## Create a release branch, assumes BRANCH_VERSION is passed in. DEPRECATED: Use release-milestone-from-master instead. - @if [ -z "${BRANCH_VERSION}" ]; then { echo "ERROR: BRANCH_VERSION should be set! Exiting..."; exit 1; }; fi - - # Create the release branch. - @echo "Creating new release branch release/v${BRANCH_VERSION}" - git checkout -b release/v${BRANCH_VERSION} - - # Create the library locks - ./gradlew allDeps --write-locks - find . -name '*.lockfile' | grep -v '/build/' | xargs git add - git commit -m "Creating release branch ${BRANCH_VERSION}, updating dependency locking" - - # Update versions - echo "${BRANCH_VERSION}.0" > VERSION - git add VERSION - git commit -m "Updating version to ${BRANCH_VERSION}.0 on release/v${BRANCH_VERSION}." - - # Push to the branch - git push -u origin release/v${BRANCH_VERSION} - - # Must also Call update-master-version. - - -update-release-version: ## Update version on the development branch, assumes BRANCH_VERSION, NEW_VERSION is passed in. DEPRECATED: Use release-milestone-from-master instead. - @if [ -z "${BRANCH_VERSION}" ]; then { echo "ERROR: BRANCH_VERSION should be set! Exiting..."; exit 1; }; fi - @if [ -z "${NEW_VERSION}" ]; then { echo "ERROR: NEW_VERSION should be set! Exiting..."; exit 1; }; fi - - # Check out the release branch - git checkout release/v${BRANCH_VERSION} - git pull - git submodule update --init --recursive - - # Update the version numbers - echo "${NEW_VERSION}" > VERSION - git add VERSION - - # Commit and push to the branch - git commit -m "Updated version to ${NEW_VERSION} on on release/v${BRANCH_VERSION}." - git push - - -release-from-release: ## Release from the given release branch. Assumes BRANCH_VERSION is passed in. DEPRECATED: Use release-milestone-from-master instead. - @if [ -z "${BRANCH_VERSION}" ]; then { echo "ERROR: BRANCH_VERSION should be set! Exiting..."; exit 1; }; fi - - # Check out release the branch - git checkout release/v${BRANCH_VERSION} - git pull - - # git tag -a ${CURRENT_TAG_VERSION} -m "Releasing gor-services ${CURRENT_TAG_VERSION}" - # git push origin $(CURRENT_TAG_VERSION) # # Misc diff --git a/VERSION b/VERSION deleted file mode 100644 index 9f7a8aa94..000000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -5.13.1 diff --git a/build.gradle b/build.gradle index 2fa82f6ef..56b9333ea 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,6 @@ buildscript { plugins { id 'idea' - id "org.ajoberstar.grgit" id "kr.motd.sphinx" apply false // Plugins not applied everywhere. @@ -58,13 +57,63 @@ plugins { id("net.razvan.jacoco-to-cobertura") version "1.1.2" // TODO: Add classpath "gradle.plugin.com.gitlab.stfs.gradle.dependencygraph:gradle-dependency-graph-plugin:latest.release" + + id 'me.qoomon.git-versioning' } apply plugin: "com.gitlab.stfs.gradle.dependency-graph-plugin" +// Version is derived from git tags (vX.Y.Z), see CONTRIBUTING.md#release. +// Tag checkout -> X.Y.Z, anything else -> -SNAPSHOT. Override with -Pversion=... +try { + gitVersioning.apply { + // https://github.com/qoomon/gradle-git-versioning-plugin + refs { + // Only tag checkouts (detached HEAD, as in the CI tag builds) get the release version, branch builds + // are always snapshots, so re-running a main build after the release is tagged never publishes X.Y.Z. + considerTagsOnBranches = false + + tag('v(?\\d+\\.\\d+\\.\\d+)') { + version = '${ref.version}' + } + + branch('.+') { + describeTagPattern = ~'v(?\\d+\\.\\d+\\.\\d+)' + version = '${describe.tag.version}-SNAPSHOT' + } + } + + // Fallback, e.g. detached HEAD that is not on a tag. + rev { + describeTagPattern = ~'v(?\\d+\\.\\d+\\.\\d+)' + version = '${describe.tag.version}-SNAPSHOT' + } + } +} catch (Exception e) { + // E.g. a shallow clone without tags, CI checkouts must use fetch-depth: 0. + logger.warn("WARNING: Could not derive version from git tags, using 0.0.0-SNAPSHOT: ${e.message}") + allprojects { + version = '0.0.0-SNAPSHOT' + } +} + +// The git versioning plugin overrides project.version, so re-apply an explicit -Pversion. +def explicitVersion = gradle.startParameter.projectProperties['version'] +if (explicitVersion) { + allprojects { version = explicitVersion } +} + +tasks.register('printVersion') { + description = 'Prints the project version (derived from git tags).' + def projectVersion = project.version + doLast { + println projectVersion + } +} + ext { // Get the git SHA to use in manifests. Do this on top level to avoid executing many times in subprojects. - gitSHA = grgit.head().id + gitSHA = ['git', 'rev-parse', 'HEAD'].execute(null, rootDir).text.trim() ?: 'unknown' } gradleLint { diff --git a/buildSrc/src/main/groovy/gor.common.gradle b/buildSrc/src/main/groovy/gor.common.gradle index 65abddb89..11c02ba1e 100644 --- a/buildSrc/src/main/groovy/gor.common.gradle +++ b/buildSrc/src/main/groovy/gor.common.gradle @@ -27,7 +27,6 @@ plugins { // ----------------------------------------------------- description = """GOR Gradle build script""" -version = hasProperty('version') && version != 'unspecified' ? version : new File("${rootDir}/VERSION").text.trim() ext { getProjectFullName = { diff --git a/buildSrc/src/main/scripts/release_milestone_from_master.sh b/buildSrc/src/main/scripts/release_milestone_from_master.sh deleted file mode 100755 index be638f8af..000000000 --- a/buildSrc/src/main/scripts/release_milestone_from_master.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash -# ----------------------------- -# Script to release given a milestone number. -# -# release_milestone_from_master.sh [] -# -# The script: -# -# 1. Validates that milestone exists and is open. -# 2. if is true then set the VERSION file equal to the milestone and pushes it. -# 3. Creates release notes from the milestone. -# 4. Creates a release (tags the the current master branch) -# 5. Closes the milestone. -# ----------------------------- - -set -e - -PROJECT_ID=$1 -MILESTONE=$2 -DRY_RUN=${3:-FALSE} - -if [ -z "${PROJECT_ID}" ]; then { echo "ERROR: PROJECT_ID should be passed in! Exiting..."; exit 1; }; fi -if [ -z "${MILESTONE}" ]; then { echo "ERROR: MILESTONE should be passed in! Exiting..."; exit 1; }; fi - -TOKEN=$(cat ~/.gradle/gradle.properties | grep -e '^gitlab_token=' | cut -d'=' -f2) -MILESTONE_JSON=$(curl --silent --header "PRIVATE-TOKEN: ${TOKEN}" "https://gitlab.com/api/v4/projects/${PROJECT_ID}/milestones?title=${MILESTONE}" | sed 's/\n/ /g') -MILESTONE_ID=$(printf "%s" ${MILESTONE_JSON} | jq '.[].id') -MILESTONE_STATE=$(printf "%s" ${MILESTONE_JSON} | jq '.[].state' | sed -e 's/^"//' -e 's/"$//') -MILESTONE_DESCRIPTION=$(printf "%s" ${MILESTONE_JSON} | jq '.[].description' | sed -e 's/^"//' -e 's/"$//') - -if [ -z "${MILESTONE_ID}" ]; then { echo "Milestone ${MILESTONE} does not exists, create the milestone and update the issues."; exit 1; }; fi -if [[ "${MILESTONE_STATE}" != "active" ]]; then { echo "Milestone ${MILESTONE} has to be open, make sure you have the right milestone."; exit 1; }; fi - -# -# Update the version -# -if [[ "${DRY_RUN}" != "TRUE" ]]; then - # Check out the release branch - git checkout master - git pull - - # Update the version numbers - echo "${MILESTONE}" > VERSION - git add VERSION - - # Commit and push to the branch - git commit -m "Updated version to ${MILESTONE}" - git push -else - echo "Release version: ${MILESTONE}" -fi - -# -# Tag -# - -RELEASE_NOTES="" -RELEASE_NOTES=${RELEASE_NOTES}$( [ ! -z ${MILESTONE_DESCRIPTION} ] && printf "### Description:\\\\r\\\\n%s\\\\r\\\\n" "${MILESTONE_DESCRIPTION}" || printf "") -RELEASE_NOTES=${RELEASE_NOTES}$(curl --silent --header "PRIVATE-TOKEN: ${TOKEN}" "https://gitlab.com/api/v4/projects/${PROJECT_ID}/milestones/${MILESTONE_ID}/issues" \ - | jq -r '.[] | select( .labels | contains(["TechDebt"]) | not) | "\( .title | (split("\"") | join(" "))) (\(.labels[0]))"' \ - | awk 'BEGIN {ORS=""; print "### Issues\\r\\n"} {print "* " $0 "\\r\\n"} END {print ""}') -printf "%s" $RELEASE_NOTES -printf "\n" - -DATA_JSON='{ "name": "'"v${MILESTONE}"'", "tag_name": "'"v${MILESTONE}"'", "ref": "master", "description": "'"${RELEASE_NOTES}"'", "milestones": ["'"${MILESTONE}"'"] }' - -printf "%s" $DATA_JSON | jq -if [[ "${DRY_RUN}" != "TRUE" ]]; then - curl --silent --header 'Content-Type: application/json' --header "PRIVATE-TOKEN: ${TOKEN}" --data "${DATA_JSON}" --request POST "https://gitlab.com/api/v4/projects/${PROJECT_ID}/releases" | jq -fi -# -# Close the milestone. -# -if [[ "${DRY_RUN}" != "TRUE" ]]; then - curl --verbose --header "PRIVATE-TOKEN: ${TOKEN}" -X PUT "https://gitlab.com/api/v4/projects/${PROJECT_ID}/milestones/${MILESTONE_ID}?state_event=close" -fi -# -# Update the version -# -# Comment this out for now, we are experimenting with just let the VERSION file refer to latest released version. -#if [[ "${DRY_RUN}" != "TRUE" ]]; then -# # Update the version numbers -# NEW_VERSION="$(buildSrc/src/main/scripts/version.sh ${MILESTONE} feature)-SNAPSHOT" -# echo ${NEW_VERSION} > VERSION -# git add VERSION -# -# # Commit and push to the branch -# git commit -m "Updated version to ${NEW_VERSION}" -# git push -#else -# echo "New snapshot version: $(buildSrc/src/main/scripts/version.sh ${MILESTONE} feature)-SNAPSHOT" -#fi \ No newline at end of file diff --git a/buildSrc/src/main/scripts/version.sh b/buildSrc/src/main/scripts/version.sh deleted file mode 100755 index a72f23367..000000000 --- a/buildSrc/src/main/scripts/version.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -version="$1" -major=0 -minor=0 -build=0 - -# break down the version number into it's components -regex="([0-9]+).([0-9]+).([0-9]+)" -if [[ $version =~ $regex ]]; then - major="${BASH_REMATCH[1]}" - minor="${BASH_REMATCH[2]}" - build="${BASH_REMATCH[3]}" -fi - -# check paramater to see which number to increment -if [[ "$2" == "major" ]]; then - major=$(echo $major+1 | bc) - minor="0" - build="0" -elif [[ "$2" == "feature" ]]; then - minor=$(echo $minor + 1 | bc) - build="0" -elif [[ "$2" == "bug" ]]; then - build=$(echo $build + 1 | bc) -else - echo "usage: ./version.sh version_number [major/feature/bug]" - exit -1 -fi - -# echo the new version number -echo "${major}.${minor}.${build}" \ No newline at end of file diff --git a/versions.properties b/versions.properties index 54412251c..6102a8b4f 100644 --- a/versions.properties +++ b/versions.properties @@ -26,9 +26,9 @@ plugin.kr.motd.sphinx=2.9.0 ## # available=2.10.0 ## # available=2.10.1 -plugin.nebula.lint=21.2.3 +plugin.me.qoomon.git-versioning=6.4.4 -plugin.org.ajoberstar.grgit=5.3.3 +plugin.nebula.lint=21.2.3 plugin.org.owasp.dependencycheck=13.0.0