From 99e5ff04ccfa3784a4fe4d78487aaea03d51befc Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Fri, 4 Aug 2023 13:23:01 -0500 Subject: [PATCH 1/3] Bring release process in line with metal-go --- .github/workflows/release.yaml | 40 +++++++++++++++++++++++++++++++++ .releaserc.json | 41 ++++++++++++++++++++++++++++++++++ Makefile | 4 ++++ spec/oas3.config.json | 2 -- version | 1 + 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 .releaserc.json create mode 100644 version diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..4575fc9f9 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,40 @@ +name: generate-release +# This workflow will generate changelog and release notes. +# Source: https://github.com/terraform-aws-modules/terraform-aws-vpc/blob/master/.github/workflows/release.yml + +on: + workflow_dispatch: + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ssh-key: ${{ secrets.DEPLOY_KEY }} + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Release + uses: cycjimmy/semantic-release-action@v3.4.2 + with: + semantic_version: 19.0.5 + extra_plugins: | + @semantic-release/exec@6.0.3 + @semantic-release/git@10.0.0 + conventional-changelog-conventionalcommits@4.6.3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GIT_AUTHOR_NAME: equinix-labs@auto-commit-workflow + GIT_AUTHOR_EMAIL: bot@equinix.noreply.github.com + GIT_COMMITTER_NAME: equinix-labs@auto-commit-workflow + GIT_COMMITTER_EMAIL: bot@equinix.noreply.github.com diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 000000000..160dd8123 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,41 @@ +{ + "branches": [ + "main" + ], + "ci": false, + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/github", + { + "successComment": "This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:", + "labels": false, + "releasedLabels": false + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "echo -n '${nextRelease.version}' > version && make generate" + } + ], + [ + "@semantic-release/git", + { + "message": "ci: regenerate code for version ${nextRelease.version}", + "assets": ["."] + } + ] + ] + } diff --git a/Makefile b/Makefile index 5cea00a2d..6dc0e5c31 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,8 @@ OPENAPI_URL=https://api.equinix.com/metal/v1/api-docs GIT_ORG=equinix-labs GIT_REPO=metal-java +PACKAGE_VERSION=$(shell cat version) + # Equinix Metal OAS 3.0.0 OPENAPI_CONFIG:=spec/oas3.config.json OPENAPI_GENERATED_CLIENT=equinix-openapi-metal/ @@ -47,6 +49,8 @@ pull: codegen: ${DOCKER_OPENAPI} generate \ + --http-user-agent "${GIT_REPO}/${PACKAGE_VERSION}" \ + -p artifactVersion=${PACKAGE_VERSION} \ -i /local/${PATCHED_SPEC_ENTRY_POINT} \ -g java \ -c /local/${OPENAPI_CONFIG} \ diff --git a/spec/oas3.config.json b/spec/oas3.config.json index eea090395..bfc1ffd94 100644 --- a/spec/oas3.config.json +++ b/spec/oas3.config.json @@ -1,8 +1,6 @@ { "groupId": "com.equinix", "artifactId": "equinix-openapi-metal", - "artifactVersion": "0.7.0", - "httpUserAgent": "metal-java/0.7.0", "library": "okhttp-gson", "invokerPackage": "com.equinix.openapi", "modelPackage": "com.equinix.openapi.metal.v1.model", diff --git a/version b/version new file mode 100644 index 000000000..faef31a43 --- /dev/null +++ b/version @@ -0,0 +1 @@ +0.7.0 From 674a6faa9152a0697dca7cf67f34133ec57cbe1a Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Fri, 4 Aug 2023 14:13:05 -0500 Subject: [PATCH 2/3] publish pom from release action --- .github/workflows/maven-publish.yml | 38 ----------------------------- .releaserc.json | 3 ++- 2 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 .github/workflows/maven-publish.yml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml deleted file mode 100644 index 790b76ed7..000000000 --- a/.github/workflows/maven-publish.yml +++ /dev/null @@ -1,38 +0,0 @@ -# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path - -name: Maven publish package - -on: - push: - tags: - # listen to tags that starts with the letter v as a convention to release tags. - - v* - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Build with Maven - working-directory: ./equinix-openapi-metal - run: mvn -B package --file pom.xml - - - name: Publish to GitHub Packages Apache Maven - working-directory: ./equinix-openapi-metal - run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/equinix-labs/metal-java - env: - GITHUB_TOKEN: ${{ github.token }} diff --git a/.releaserc.json b/.releaserc.json index 160dd8123..062114060 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -27,7 +27,8 @@ [ "@semantic-release/exec", { - "prepareCmd": "echo -n '${nextRelease.version}' > version && make generate" + "prepareCmd": "echo -n '${nextRelease.version}' > version && make generate", + "publishCmd": "mvn -f equinix-openapi-metal -B package && mvn -f equinix-openapi-metal deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/equinix-labs/metal-java" } ], [ From c91249ac2ed5269b56de886684bb0c901b24fdcb Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Fri, 29 Sep 2023 09:45:01 -0500 Subject: [PATCH 3/3] Document release workflow in README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 00c6837ab..23278bb25 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ make generate ``` ## Contribution guidelines + ### Patching oas3.0 spec 1. Make changes in ``spec/oas3.patched/`` dir. 2. Create a patch file in metal-java: @@ -74,3 +75,17 @@ Complex workflows requiring multiple granular, autogenerated apis can be impleme 4. If using environment variables, they can be added in Java options. 4. Alternatively, you can do step iii through terminal directly. 4. For every new functional test, a separate github workflow .yaml should be defined inside ```.github/workflows```. These can be run from Github's actions UI directly. Check existing workflow definitions for reference. + +## Release + +This SDK is released via [an on-demand GitHub Actions workflow](https://github.com/equinix-labs/metal-go/actions/workflows/release.yaml). + +When that workflow is run, it steps through the release process in roughly this order: + +1. Determine the version number of the previous GitHub release +2. Identify Conventional Commit tags in the commit log since the previous release +3. Use the Conventional Commit tags to calculate the correct next version +4. Write the next version to the `version` file and regenerate the code +5. Commit the updated `version` and code +6. Create a GitHub release using the value in `version` for the tag & title +7. Rebuild SDK JARs and publish them to [this repo's packages page](https://github.com/equinix-labs/metal-java/packages/)