From 3681a824bb79c81800dc0e3dde4d23ae4b166163 Mon Sep 17 00:00:00 2001 From: ds-pweick <162321742+ds-pweick@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:44:55 +0200 Subject: [PATCH 1/3] fix: Proper release workflow (#727) * refactor(release): improve release workflow --- .github/workflows/helm-chart-release.yaml | 12 +- .github/workflows/irs-build.yml | 19 +- .github/workflows/publish-swagger-hub.yml | 50 ---- .github/workflows/release.yaml | 227 +++++++++++++++--- .github/workflows/swagger-editor-validate.yml | 13 +- .github/workflows/trivy-docker-hub-scan.yml | 8 + .github/workflows/trivy-image-scan.yml | 11 +- .github/workflows/update-docs-for-release.yml | 184 -------------- CONTRIBUTING.md | 101 +++++--- docs/src/api/irs-api.yaml | 2 +- 10 files changed, 323 insertions(+), 304 deletions(-) delete mode 100644 .github/workflows/publish-swagger-hub.yml delete mode 100644 .github/workflows/update-docs-for-release.yml diff --git a/.github/workflows/helm-chart-release.yaml b/.github/workflows/helm-chart-release.yaml index 529bdd3289..49d51cae90 100644 --- a/.github/workflows/helm-chart-release.yaml +++ b/.github/workflows/helm-chart-release.yaml @@ -2,6 +2,12 @@ name: Release Helm Charts on: workflow_dispatch: # Trigger manually + workflow_call: + inputs: + ref-to-check-out: + description: 'Ref of branch/tag from which to execute workflow' + required: true + type: string push: branches: - main @@ -21,6 +27,8 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + fetch-tags: 'true' + ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Get helm charts latest tag version id: step1 @@ -36,7 +44,7 @@ jobs: echo "Exported $chartVersion helm charts version" release: - needs: "get-helm-charts-versions-irs" + needs: [get-helm-charts-versions-irs] if: needs.get-helm-charts-versions-irs.outputs.latest_version != needs.get-helm-charts-versions-irs.outputs.current_version # depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions # see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token @@ -48,6 +56,8 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + fetch-tags: 'true' + ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Configure Git run: | diff --git a/.github/workflows/irs-build.yml b/.github/workflows/irs-build.yml index e04ffd449e..01069a91e9 100644 --- a/.github/workflows/irs-build.yml +++ b/.github/workflows/irs-build.yml @@ -2,6 +2,13 @@ name: IRS build on: workflow_dispatch: # Trigger manually + workflow_call: + inputs: + ref-to-check-out: + description: 'Ref of branch/tag from which to execute workflow' + required: true + type: string + pull_request: paths-ignore: - '**/*.md' @@ -26,6 +33,9 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-tags: 'true' + ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Set up JDK 17 uses: actions/setup-java@v4 @@ -66,7 +76,9 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of sonar analysis + fetch-depth: 0 + fetch-tags: 'true' + ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Set up JDK 17 uses: actions/setup-java@v4 @@ -108,6 +120,9 @@ jobs: image-tag: ${{ steps.version.outputs.image_tag }} steps: - uses: actions/checkout@v4 + with: + fetch-tags: 'true' + ref: ${{ inputs.ref-to-check-out || github.ref }} # Needed to create multi-platform image - name: Set up Docker Buildx @@ -168,3 +183,5 @@ jobs: needs: - build_images uses: ./.github/workflows/trivy-docker-hub-scan.yml + with: + ref-to-check-out: ${{ inputs.ref-to-check-out || github.ref }} diff --git a/.github/workflows/publish-swagger-hub.yml b/.github/workflows/publish-swagger-hub.yml deleted file mode 100644 index 1fef7d9354..0000000000 --- a/.github/workflows/publish-swagger-hub.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: "Publish OpenAPI to Swaggerhub" - -on: - workflow_call: - inputs: - version: - required: true - description: Version that will be published to Swaggerhub - type: string - -jobs: - swagger-api: - runs-on: ubuntu-latest - env: - SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_API_KEY }} - SWAGGERHUB_USER: ${{ secrets.SWAGGERHUB_USER }} - DOWNSTREAM_VERSION: ${{ inputs.version }} - steps: - - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - - name: Setup node - uses: actions/setup-node@v4 - - - name: Install Swagger CLI - run: | - npm i -g swaggerhub-cli - - # create API, will fail if exists - - name: Create API - continue-on-error: true - run: | - swaggerhub api:create ${{ env.SWAGGERHUB_USER }}/item-relationship-service/${{ env.DOWNSTREAM_VERSION }} -f docs/src/api/irs-api.yaml --visibility=public --published=unpublish - - # Post the API to SwaggerHub as "unpublished", because published APIs cannot be overwritten - - name: Publish API Specs to SwaggerHub - run: | - if [[ ${{ env.DOWNSTREAM_VERSION }} != *-SNAPSHOT ]]; then - echo "[INFO] - no snapshot, will set the API to 'published'"; - swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/item-relationship-service/${{ env.DOWNSTREAM_VERSION }} -f docs/src/api/irs-api.yaml --visibility=public --published=publish - swaggerhub api:setdefault ${{ env.SWAGGERHUB_USER }}/item-relationship-service/${{ env.DOWNSTREAM_VERSION }} - else - echo "[INFO] - snapshot, will set the API to 'unpublished'"; - swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/item-relationship-service/${{ env.DOWNSTREAM_VERSION }} -f docs/src/api/irs-api.yaml --visibility=public --published=unpublish - fi diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 010c312c8a..c46b919601 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,72 +1,245 @@ name: Release IRS on: - workflow_call: + workflow_dispatch: inputs: - new-irs-version: + irs-version: description: 'New IRS version' required: true type: string - previous-irs-version: - description: 'Previous IRS version' - required: true - type: string + helm-chart-version: description: 'New Helm Chart version' required: true type: string + add-change-to-helm-changelog: + description: 'Add "Update IRS to ..." change to Helm Chart changelog' + required: true + type: boolean + default: true + +env: + IRS_APPLICATION_PATH: 'irs-api/src/main/java/org/eclipse/tractusx/irs/IrsApplication.java' + CHANGELOG_PATH: 'CHANGELOG.md' + OPENAPI_SPEC_PATH: 'docs/src/api/irs-api.yaml' + HELM_CHART_PATH: 'charts/item-relationship-service' + SEMVER_PATTERN: '[0-9]+\.[0-9]+\.[0-9]+' + SEMVER_PATTERN_SED: '[0-9]\+\.[0-9]\+\.[0-9]\+\' + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Validate that workflow inputs are SemVer strings + run: | + matched_irs_semver_string=$(echo "${{ inputs.irs-version }}" | grep -Ex "${{ env.SEMVER_PATTERN }}" || echo "") + matched_helm_chart_semver_string=$(echo "${{ inputs.helm-chart-version }}" | grep -Ex "${{ env.SEMVER_PATTERN }}" || echo "") + if [[ -z "$matched_irs_semver_string" || -z "$matched_helm_chart_semver_string" ]]; then + echo "At least one of the version numbers ${{ inputs.irs-version }} or ${{ inputs.helm-chart-version }} is not a SemVer string." + exit 1 + fi + continue-on-error: false + + - name: Validate that IRS and Helm Chart versions don't exist yet + run: | + # IRS version can be checked via git tag since every release has a tag + matched_irs_version=$(git tag | grep -Eo "${{ inputs.irs-version }}" || echo "") + # extract from Helm Chart changelog + matched_helm_chart_version=$(grep -Eo "## \[${{ inputs.helm-chart-version }}\]" ${{ env.HELM_CHART_PATH }}/CHANGELOG.md || echo "") + + if [[ -n "$matched_irs_version" || -n "$matched_helm_chart_version" ]]; then + echo "At least one of the version numbers ${{ inputs.irs-version }} or ${{ inputs.helm-chart-version }} already exists." + exit 1 + fi + continue-on-error: false + + - name: Update changelog + id: main-changelog-update + run: | + date=$(date +"%Y-%m-%d") + + # get line number of uppermost comparison url at bottom of changelog ("[Unreleased]: https://github.com/.../version...HEAD") + latest_comparison_url_line_number=$(cat -n ${{ env.CHANGELOG_PATH }} | grep -Eoi "[0-9]+.\[Unreleased\]" | grep -Eo "[0-9]+") + + # previous version can be extracted from line below uppermost comparison + previous_irs_version=$(awk "NR==$((latest_comparison_url_line_number+1))" ${{ env.CHANGELOG_PATH }} | grep -Eo "\[${{ env.SEMVER_PATTERN }}\]" | tr -d "[]") + echo "previous-irs-version=$previous_irs_version" >> "$GITHUB_OUTPUT" + + # correct uppermost comparison + sed -i "$latest_comparison_url_line_number s|${{ env.SEMVER_PATTERN_SED }}\.\.\.HEAD|${{ inputs.irs-version }}...HEAD|" ${{ env.CHANGELOG_PATH }} + + # insert new comparison below uppermost one + sed -i "$((latest_comparison_url_line_number+1)) s|^|[${{ inputs.irs-version }}]: \ + https://github.com/eclipse-tractusx/item-relationship-service/compare/$previous_irs_version...${{ inputs.irs-version }}\n|" ${{ env.CHANGELOG_PATH }} + + # replace placeholder + placeholder_line_number=$(cat -n ${{ env.CHANGELOG_PATH }} | grep -Eoi "[0-9]+.## \[Unreleased\]" | grep -Eo "[0-9]+") + sed -i "$((placeholder_line_number+1)) s|^|\n## [${{ inputs.irs-version }}] - $date\n|" ${{ env.CHANGELOG_PATH }} + + - name: Update Helm changelog + run: | + date=$(date +"%Y-%m-%d") + + ### update Helm Chart directory's CHANGELOG.md ### + helm_changelog_placeholder_line_number=$(cat -n ${{ env.HELM_CHART_PATH }}/CHANGELOG.md | grep -Eoi "[0-9]+.## \[Unreleased\]" | grep -Eo "[0-9]+") + + if [[ "${{ inputs.add-change-to-helm-changelog }}" == "true" ]]; then + # get line number of first header which is not placeholder + next_header_line_number=$(cat -n ${{ env.HELM_CHART_PATH }}/CHANGELOG.md | grep -Eo -m 1 "[0-9]+.## \[${{ env.SEMVER_PATTERN }}\]" | grep -Eo "^[0-9]+") + + # get line number of first "### Changed" section + first_changed_section_line_number=$(cat -n ${{ env.HELM_CHART_PATH }}/CHANGELOG.md | grep -Eo -m 1 "[0-9]+.### Changed" | grep -Eo "[0-9]+") + + # "### Changed" is already present for current changelog if it comes before next header -> just insert line below + if [[ $first_changed_section_line_number -lt $next_header_line_number ]]; then + + # check if markdown was properly formatted (with blank line between "### Changed" and first change) + line_after=$(awk "NR==$((first_changed_section_line_number+1))" ${{ env.HELM_CHART_PATH }}/CHANGELOG.md) + + if [[ "$line_after" == "" ]]; then + sed -i "$((first_changed_section_line_number+1)) s|^|\n- Update IRS version to ${{ inputs.irs-version }}|" ${{ env.HELM_CHART_PATH }}/CHANGELOG.md + else # format properly with blank line + sed -i "$((first_changed_section_line_number+1)) s|^|\n- Update IRS version to ${{ inputs.irs-version }}\n|" ${{ env.HELM_CHART_PATH }}/CHANGELOG.md + fi + + else + sed -i "$((helm_changelog_placeholder_line_number+1)) s|^|\n### Changed\n\n- Update IRS version to ${{ inputs.irs-version }}\n|" ${{ env.HELM_CHART_PATH }}/CHANGELOG.md + fi + fi + + # replace placeholder + helm_changelog_placeholder_line_number=$(cat -n ${{ env.HELM_CHART_PATH }}/CHANGELOG.md | grep -Eoi "[0-9]+.## \[Unreleased\]" | grep -Eo "[0-9]+") + sed -i "$((helm_changelog_placeholder_line_number+1)) s|^|\n## [${{ inputs.helm-chart-version }}] - $date\n|" ${{ env.HELM_CHART_PATH }}/CHANGELOG.md + + - name: Update IrsApplication.java + run: sed -i "s|${{ steps.main-changelog-update.outputs.previous-irs-version }}|${{ inputs.irs-version }}|" ${{ env.IRS_APPLICATION_PATH }} + + - name: Update irs-api.yaml + uses: mikefarah/yq@v4.44.2 + with: + cmd: yq -i eval '.info.version = "${{ inputs.irs-version }}"' ${{ env.OPENAPI_SPEC_PATH }} + - name: Update Chart.yaml appVersion uses: mikefarah/yq@v4.44.2 with: - cmd: yq -i eval '.appVersion = "${{ inputs.new-irs-version }}"' charts/item-relationship-service/Chart.yaml + cmd: yq -i eval '.appVersion = "${{ inputs.irs-version }}"' ${{ env.HELM_CHART_PATH }}/Chart.yaml - name: Update Chart.yaml version uses: mikefarah/yq@v4.44.2 with: - cmd: yq -i eval '.version = "${{ inputs.helm-chart-version }}"' charts/item-relationship-service/Chart.yaml + cmd: yq -i eval '.version = "${{ inputs.helm-chart-version }}"' ${{ env.HELM_CHART_PATH }}/Chart.yaml - - name: Prepare Helm release + - name: Update docs and Helm chart for release + id: cpr uses: peter-evans/create-pull-request@v6 with: - commit-message: "chore(release): Prepare release for Helm version ${{ inputs.helm-chart-version }}" - branch: chore/prepare-helm-release-${{ inputs.helm-chart-version }} - base: main + commit-message: 'chore(docs): updated docs and Helm chart for IRS release ${{ inputs.irs-version }}' + branch: action/update-for-release-${{ inputs.irs-version }} delete-branch: true - title: Prepare Helm release for next version - body: | - This PR prepares the Helm chart release for version ${{ inputs.helm-chart-version }}. - Please check whether the Chart was updated correctly and that the CHANGELOG contains the relevant information - for this release. Also, make sure that the values.yaml is correct before merging this PR. + title: "chore: updated docs and Helm chart for release" + body: This PR prepares the docs and the Helm chart for IRS release ${{ inputs.irs-version }}. + Please check whether everything was updated correctly. Once this PR is merged, the release process will continue automatically. + + - name: Wait for pull request merge + run: | + pull_request_number=${{ steps.cpr.outputs.pull-request-number }} + pull_request_merged="False" + seconds_waited_for_merge=0 + # set duration between api requests + sleep_interval_length=5 # seconds + timeout_in_minutes=15 + + echo "Waiting for merge of PR #$pull_request_number." + + while [[ "$pull_request_merged" == "False" ]] + do + # give some time to merge pull request + sleep "$sleep_interval_length"s + + # retrieve pr status using GH API's pull requests endpoint with GH CLI + pr_status=$(gh pr view $pull_request_number --json state --jq ".state") + + case $pr_status in + + MERGED) + pull_request_merged="True" + echo "PR #$pull_request_number merged, continuing the workflow." + ;; + + OPEN) + seconds_waited_for_merge=$((seconds_waited_for_merge+sleep_interval_length)) + + # abort workflow when having waited for more than allowed time + if [[ $seconds_waited_for_merge -gt $((timeout_in_minutes*60)) ]]; then + echo "Timeout waiting for merge of PR #$pull_request_number, aborting the workflow." + exit 1 + fi + ;; + + CLOSED) + echo "PR #$pull_request_number was closed, aborting the workflow." + exit 1 + ;; + + esac + + done + continue-on-error: false + + - name: Create and push new Git tag for release and pull latest changes + run: git tag ${{ inputs.irs-version }} && git push origin ${{ inputs.irs-version }} && git pull - name: Extract changelog text # See: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings run: | EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) echo "CHANGELOG<<$EOF" >> $GITHUB_ENV - sed -n -e '/## \[${{ inputs.new-irs-version }}\]/,/## \[/ p' CHANGELOG.md | head -n -1 | tail -n +2 >> $GITHUB_ENV - echo **Full Changelog**: ${{ github.server_url }}/${{ github.repository }}/compare/${{ inputs.previous-irs-version }}...${{ inputs.new-irs-version }} >> $GITHUB_ENV + sed -n -e '/## \[${{ inputs.irs-version }}\]/,/## \[/ p' ${{ env.CHANGELOG_PATH }} | head -n -1 | tail -n +2 >> $GITHUB_ENV + echo **Full Changelog**: ${{ github.server_url }}/${{ github.repository }}/compare\ + /${{ steps.main-changelog-update.outputs.previous-irs-version }}...${{ inputs.irs-version }} >> $GITHUB_ENV echo "$EOF" >> "$GITHUB_ENV" - name: Create IRS release uses: softprops/action-gh-release@v2 with: body: ${{ env.CHANGELOG }} - tag_name: ${{ inputs.new-irs-version }} + tag_name: ${{ inputs.irs-version }} + + release-helm-chart: + name: "Release Helm chart" + needs: + - release + uses: ./.github/workflows/helm-chart-release.yaml + with: + ref-to-check-out: 'refs/tags/${{ inputs.irs-version }}' + + build-irs: + name: "Build IRS" + needs: + - release + uses: ./.github/workflows/irs-build.yml + secrets: inherit + with: + ref-to-check-out: 'refs/tags/${{ inputs.irs-version }}' + + trivy-image-scan: + name: "Scan image in local registry with Trivy" + needs: + - release + uses: ./.github/workflows/trivy-image-scan.yml + secrets: inherit + with: + ref-to-check-out: 'refs/tags/${{ inputs.irs-version }}' - publish-to-swaggerhub: - name: "Publish OpenAPI spec to Swaggerhub" - permissions: - contents: read + validate-openapi-definition: needs: - release - uses: ./.github/workflows/publish-swagger-hub.yml + name: "Validate OpenAPI definition" + uses: ./.github/workflows/swagger-editor-validate.yml + secrets: inherit with: - version: ${{ inputs.new-irs-version }} - secrets: inherit \ No newline at end of file + ref-to-check-out: 'refs/tags/${{ inputs.irs-version }}' \ No newline at end of file diff --git a/.github/workflows/swagger-editor-validate.yml b/.github/workflows/swagger-editor-validate.yml index efcecb035f..00af44cca5 100644 --- a/.github/workflows/swagger-editor-validate.yml +++ b/.github/workflows/swagger-editor-validate.yml @@ -2,6 +2,12 @@ name: "Validate OpenAPI definition" on: workflow_dispatch: # Trigger manually + workflow_call: + inputs: + ref-to-check-out: + description: 'Ref of branch/tag from which to execute workflow' + required: true + type: string pull_request: push: branches: @@ -15,7 +21,12 @@ jobs: name: Swagger Editor Validator Remote steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-tags: 'true' + ref: ${{ inputs.ref-to-check-out || github.ref }} + - name: Validate OpenAPI definition uses: char0n/swagger-editor-validate@v1 with: diff --git a/.github/workflows/trivy-docker-hub-scan.yml b/.github/workflows/trivy-docker-hub-scan.yml index 00310d2adf..2619f38b70 100644 --- a/.github/workflows/trivy-docker-hub-scan.yml +++ b/.github/workflows/trivy-docker-hub-scan.yml @@ -3,6 +3,11 @@ name: "Trivy vulnerability scanner for Docker Hub Image" on: workflow_dispatch: # Trigger manually workflow_call: # Trigger by another workflow + inputs: + ref-to-check-out: + description: 'Ref of branch/tag from which to execute workflow' + required: true + type: string schedule: - cron: "0 0 * * *" @@ -17,6 +22,9 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-tags: 'true' + ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master diff --git a/.github/workflows/trivy-image-scan.yml b/.github/workflows/trivy-image-scan.yml index 23699557cd..2bec2c5ee5 100644 --- a/.github/workflows/trivy-image-scan.yml +++ b/.github/workflows/trivy-image-scan.yml @@ -5,6 +5,12 @@ name: "Trivy vulnerability scanner for image" on: workflow_dispatch: # Trigger manually + workflow_call: + inputs: + ref-to-check-out: + description: 'Ref of branch/tag from which to execute workflow' + required: true + type: string pull_request: paths-ignore: - '**/*.md' @@ -35,8 +41,11 @@ jobs: - 5000:5000 steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 + with: + fetch-tags: 'true' + ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Build image uses: docker/build-push-action@v6 diff --git a/.github/workflows/update-docs-for-release.yml b/.github/workflows/update-docs-for-release.yml deleted file mode 100644 index 70fdf27f77..0000000000 --- a/.github/workflows/update-docs-for-release.yml +++ /dev/null @@ -1,184 +0,0 @@ -name: Update docs for IRS release - -env: - IRS_APPLICATION_PATH: 'irs-api/src/main/java/org/eclipse/tractusx/irs/IrsApplication.java' - TOP_LEVEL_CHANGELOG_PATH: 'CHANGELOG.md' - IRS_OPENAPI_SPEC_PATH: 'docs/src/api/irs-api.yaml' - IRS_HELM_CHANGELOG_PATH: 'charts/item-relationship-service/CHANGELOG.md' - SEMVER_PATTERN: '[0-9]+\.[0-9]+\.[0-9]+' - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -on: - workflow_dispatch: - inputs: - irs-version: - description: 'New IRS version' - required: true - type: string - helm-chart-version: - description: 'New Helm Chart version' - required: true - type: string - helm-changelog-irs-added: - description: '"Update IRS version to ..." change already present in charts/irs-helm/CHANGELOG.md for this release?' - required: true - type: choice - options: - - 'Yes' - - 'No' - default: 'No' -jobs: - update-docs-for-release: - runs-on: ubuntu-latest - outputs: - previous-irs-version: ${{ steps.update-docs.outputs.previous-irs-version }} - - steps: - - uses: actions/checkout@v4 - - - name: Validate that workflow inputs are SemVer strings - run: | - matched_irs_semver_string=$(echo "${{ inputs.irs-version }}" | grep -Ex "${{ env.SEMVER_PATTERN }}" || echo "") - matched_helm_chart_semver_string=$(echo "${{ inputs.helm-chart-version }}" | grep -Ex "${{ env.SEMVER_PATTERN }}" || echo "") - if [[ -z "$matched_irs_semver_string" || -z "$matched_helm_chart_semver_string" ]]; then - exit 1 - fi - continue-on-error: false - - - name: Validate that IRS and Helm Chart versions don't exist yet - run: | - # IRS version can be checked via git tag since every release has a tag - matched_irs_version=$(git tag | grep -Eo "${{ inputs.irs-version }}" || echo "") - # extract from Helm Chart changelog - matched_helm_chart_version=$(grep -Eo "## \[${{ inputs.helm-chart-version }}\]" ${{ env.IRS_HELM_CHANGELOG_PATH }} || echo "") - - if [[ -n "$matched_irs_version" || -n "$matched_helm_chart_version" ]]; then - echo "IRS or Helm Chart release version already exists, aborting..." - exit 1 - fi - continue-on-error: false - - - name: Update top level changelog, IRS Helm changelog, Helm repository's yaml file and IrsApplication.java - id: update-docs - run: | - new_irs_version="${{ inputs.irs-version }}" - new_helm_chart_version="${{ inputs.helm-chart-version }}" - irs_change_present_in_helm_changelog="${{ inputs.helm-changelog-irs-added }}" - date=$(date +"%Y-%m-%d") - - semver_pattern="${{ env.SEMVER_PATTERN }}" - semver_pattern_sed="[0-9]\+\.[0-9]\+\.[0-9]\+" - - # get line numbers of "Unreleased" or "UNRELEASED" placeholders in changelogs to use them with sed - top_lvl_changelog_placeholder_line_number=$(cat -n ${{ env.TOP_LEVEL_CHANGELOG_PATH }} | grep -Eoi "[0-9]+.## \[Unreleased\]" | grep -Eo "[0-9]+") - irs_helm_changelog_placeholder_line_number=$(cat -n ${{ env.IRS_HELM_CHANGELOG_PATH }} | grep -Eoi "[0-9]+.## \[Unreleased\]" | grep -Eo "[0-9]+") - - ### update CHANGELOG.md ### - # get line number of uppermost comparison url ("[Unreleased]: https://github.com/.../version...HEAD") - latest_comparison_url_line_number=$(cat -n ${{ env.TOP_LEVEL_CHANGELOG_PATH }} | grep -Eoi "[0-9]+.\[Unreleased\]" | grep -Eo "[0-9]+") - - # previous version can be extracted from line below uppermost comparison - previous_irs_version=$(awk "NR==$((latest_comparison_url_line_number+1))" ${{ env.TOP_LEVEL_CHANGELOG_PATH }} | grep -Eo "\[$semver_pattern\]" | tr -d "[]") - echo "previous-irs-version=$previous_irs_version" >> "$GITHUB_OUTPUT" - - # correct uppermost comparison - sed -i "$latest_comparison_url_line_number s|$semver_pattern_sed\.\.\.HEAD|$new_irs_version...HEAD|" ${{ env.TOP_LEVEL_CHANGELOG_PATH }} - - # insert new comparison below uppermost one - sed -i "$((latest_comparison_url_line_number+1)) s|^|[$new_irs_version]: https://github.com/eclipse-tractusx/item-relationship-service/compare/$previous_irs_version...$new_irs_version\n|" ${{ env.TOP_LEVEL_CHANGELOG_PATH }} - - # replace placeholder - # get line numbers of "Unreleased" placeholder in changelogs to use them with sed - top_lvl_changelog_placeholder_line_number=$(cat -n ${{ env.TOP_LEVEL_CHANGELOG_PATH }} | grep -Eoi "[0-9]+.## \[Unreleased\]" | grep -Eo "[0-9]+") - sed -i "$((top_lvl_changelog_placeholder_line_number+1)) s|^|\n## [$new_irs_version] - $date\n|" ${{ env.TOP_LEVEL_CHANGELOG_PATH }} - - ### update irs-helm directory's CHANGELOG.md ### - if [[ "$irs_change_present_in_helm_changelog" == "No" ]]; then - # get line number of first header which is not placeholder - next_header_line_number=$(cat -n ${{ env.IRS_HELM_CHANGELOG_PATH }} | grep -Eo -m 1 "[0-9]+.## \[$semver_pattern\]" | grep -Eo "^[0-9]+") - # get line number of first "### Changed" section - first_changed_section_line_number=$(cat -n ${{ env.IRS_HELM_CHANGELOG_PATH }} | grep -Eo -m 1 "[0-9]+.### Changed" | grep -Eo "[0-9]+") - - # "### Changed" is already present for current changelog if it comes before next header -> just insert line below - if [[ $first_changed_section_line_number -lt $next_header_line_number ]]; then - sed -i "$((first_changed_section_line_number+1)) s|^|- Update IRS version to $new_irs_version\n|" ${{ env.IRS_HELM_CHANGELOG_PATH }} - # not present, insert before beginning of next header - else - sed -i "$(($next_header_line_number-1)) s|^|\n### Changed\n- Update IRS version to $new_irs_version\n|" ${{ env.IRS_HELM_CHANGELOG_PATH }} - fi - fi - - # replace placeholder - irs_helm_changelog_placeholder_line_number=$(cat -n ${{ env.IRS_HELM_CHANGELOG_PATH }} | grep -Eoi "[0-9]+.## \[Unreleased\]" | grep -Eo "[0-9]+") - sed -i "$((irs_helm_changelog_placeholder_line_number+1)) s|^|\n## [$new_helm_chart_version] - $date\n|" ${{ env.IRS_HELM_CHANGELOG_PATH }} - - ### update irs-api.yaml ### - irs_openapi_spec_irs_version_line_number=$(cat -n ${{ env.IRS_OPENAPI_SPEC_PATH }} | grep -Eo -m 1 "[0-9]+.+version: $semver_pattern" | grep -Eo "^[0-9]+") - sed -i "$irs_openapi_spec_irs_version_line_number s|$semver_pattern_sed|$new_irs_version|" ${{ env.IRS_OPENAPI_SPEC_PATH }} - - ### update IrsApplication.java ### - sed -i "s|API_VERSION = \"$semver_pattern_sed\"|API_VERSION = \"$new_irs_version\"|" ${{ env.IRS_APPLICATION_PATH }} - - - name: Create pull request - id: cpr - uses: peter-evans/create-pull-request@v6 - with: - commit-message: 'chore(docs): Update docs for release ${{ inputs.irs-version }}' - branch: chore/update-docs-for-irs-release-${{ inputs.irs-version }} - base: main - delete-branch: true - title: Updated docs for next release - body: This PR prepares the docs for IRS release version ${{ inputs.irs-version }}. - Please check whether the docs were updated correctly. Once this PR is merged, the release process will continue automatically. - - - name: Wait for pull request merge - run: | - pull_request_number=${{ steps.cpr.outputs.pull-request-number }} - pull_request_merged="False" - seconds_waited_for_merge=0 - # set duration between api requests - sleep_interval_length=30 # seconds - timeout_in_minutes=10 - - while [[ "$pull_request_merged" == "False" ]] - do - # give some time to merge pull request - sleep "$sleep_interval_length"s - - # retrieve pr status using GH API's pull requests endpoint with GH CLI - pr_status=$(gh pr view $pull_request_number --json state --jq ".state") - - case $pr_status in - - MERGED) - pull_request_merged="True" - ;; - - OPEN) - seconds_waited_for_merge=$((seconds_waited_for_merge+sleep_interval_length)) - # abort workflow when having waited for more than specified time - if [[ $seconds_waited_for_merge -gt $((timeout_in_minutes*60)) ]]; then - exit 1 - fi - ;; - - CLOSED) - exit 1 - ;; - - esac - - done - continue-on-error: false - - - name: Create and push new Git tag for release - run: git tag ${{ inputs.irs-version }} && git push origin ${{ inputs.irs-version }} - - call-release-workflow: - needs: - - update-docs-for-release - uses: ./.github/workflows/release.yaml - with: - new-irs-version: ${{ inputs.irs-version }} - previous-irs-version: ${{ needs.update-docs-for-release.outputs.previous-irs-version }} - helm-chart-version: ${{ inputs.helm-chart-version }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64994e7a02..972e37eb02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,6 +3,7 @@ Thanks for your interest in this project. # Table of Contents + 1. [Project description](#project-description) 2. [Project licenses](#project-licenses) 3. [Terms of Use](#terms-of-use) @@ -88,7 +89,9 @@ See [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md). ## Eclipse Dependency License Check -In case of new dependencies or version updates, it might be necessary to have the new library checked and accepted by the Eclipse foundation. Do create new tickets for this, you can use this command: +In case of new dependencies or version updates, it might be necessary to have the new library checked and accepted by +the Eclipse foundation. Do create new tickets for this, you can use this command: + ``` mvn org.eclipse.dash:license-tool-plugin:license-check -Ddash.iplab.token=$ECLIPSE_DASH_TOKEN -Ddash.projectId=automotive.tractusx --batch-mode -DskipTests -P dash ``` @@ -99,30 +102,37 @@ For more information on the tool and how to acquire the token, check https://git General contributions e.g. contributions to improve documentation are welcome. If you need ideas for contributions, you can check the following links: + - [open documentation stories](https://github.com/orgs/eclipse-tractusx/projects/8/views/4?filterQuery=label%3Adocumentation++status%3Ainbox%2Cbacklog) - [discussion page concerning documentation improvements](https://github.com/eclipse-tractusx/item-relationship-service/discussions/407) -### Maintaining [CHANGELOG.md](CHANGELOG.md) +### Maintaining [CHANGELOG.md](CHANGELOG.md) + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres -to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). _**For better traceability add the corresponding GitHub issue number in each changelog entry, please.**_ ## Contributing as a Consultant ### Conceptual work and specification guidelines -1. The prerequisite for a concept is always a GitHub issue that defines the business value and the acceptance criteria that are to be implemented with the concept + +1. The prerequisite for a concept is always a GitHub issue that defines the business value and the acceptance criteria + that are to be implemented with the concept 2. Copy and rename directory /docs/#000-concept-name-template /docs/#- -3. Copy the template file [/docs/concept/TEMPLATE_Concept.md](docs/concept/TEMPLATE_Concept.md) into new directory `/docs/#-`. +3. Copy the template file [/docs/concept/TEMPLATE_Concept.md](docs/concept/TEMPLATE_Concept.md) into new + directory `/docs/#-`. ### Diagrams + [PlantUML](https://plantuml.com/) and [Mermaid](https://mermaid.js.org/) is used for conceptual work. +#### PlantUML + +default skinparam for plantUml diagrams -#### PlantUML -default skinparam for plantUml diagrams ```` @startuml skinparam monochrome true @@ -134,8 +144,10 @@ autonumber "[000]" @enduml ```` -#### Mermaid +#### Mermaid + Default header for mermaid sequence diagrams + ```` sequenceDiagram %%{init: {'theme': 'dark', 'themeVariables': { 'fontSize': '15px'}}}%% @@ -157,6 +169,7 @@ Example: Detailed pattern can be found here: [commit-msg](local/development/commit-msg) #### How to Use + ```shell cp local/development/commit-msg .git/hooks/commit-msg && chmod 500 .git/hooks/commit-msg ``` @@ -166,11 +179,15 @@ For further information please see https://github.com/hazcod/semantic-commit-hoo ### Code Formatting #### Deprecated soon: + Please use the following code formatter: [.idea/codeStyles](.idea/codeStyles) -#### Upcoming change (not available until whole project base will be formatted to new standard): +#### Upcoming change (not available until whole project base will be formatted to new standard): + Google Java Format will be used as code format standard. -Please install `google-java-format` plugin and edit customer VM options (for IntelliJ `Help → Edit Custom VM Options...`) and paste following configuration: +Please install `google-java-format` plugin and edit customer VM options (for +IntelliJ `Help → Edit Custom VM Options...`) and paste following configuration: + ``` -Xmx4096m --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED @@ -180,54 +197,62 @@ Please install `google-java-format` plugin and edit customer VM options (for Int --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED ``` -The plugin will be disabled by default. To enable it in the current project, go to `File→Settings...→google-java-format` Settings (or `IntelliJ IDEA→Preferences...→Other Settings→google-java-format` Settings on macOS) and check the Enable google-java-format checkbox. (A notification will be presented when you first open a project offering to do this for you.) + +The plugin will be disabled by default. To enable it in the current project, go to `File→Settings...→google-java-format` +Settings (or `IntelliJ IDEA→Preferences...→Other Settings→google-java-format` Settings on macOS) and check the Enable +google-java-format checkbox. (A notification will be presented when you first open a project offering to do this for +you.) More info: https://github.com/google/google-java-format/blob/master/README.md#intellij-jre-config ### Create a Release -#### Full release +### Full release 1. Choose a release version using [semantic versioning](https://semver.org/spec/v2.0.0.html) and create a corresponding branch according to the template: `chore/prepare-release-x.x.x`. 2. Add release notes for new version in [CHANGELOG.md](CHANGELOG.md) and [charts/item-relationship-service/CHANGELOG.md](charts/item-relationship-service/CHANGELOG.md) (for an example [see here](https://github.com/eclipse-tractusx/item-relationship-service/pull/429)) - - Check if the changelog entries for the release are complete. - - Add the corresponding GitHub issue numbers to each entry if missing. + - Check if the changelog entries for the release are complete. + - Add the corresponding GitHub issue numbers to each entry if missing. 3. Update [COMPATIBILITY_MATRIX.md](COMPATIBILITY_MATRIX.md). -4. Update IRS API version in IrsApplication class and irs-api.yaml -5. Create pull request from [release preparation branch to main](https://github.com/eclipse-tractusx/item-relationship-service/compare/chore/prepare-release-x.x.x) -6. Merge this pull request to main. -7. Create Git tag for the desired release version `git tag x.x.x` - (note: the _item-relationship-service_ tag will be created automatically by the GitHub workflow based on the version in the [helm chart changelog](charts/item-relationship-service/CHANGELOG.md)). -8. Push Git tag to repository `git push origin x.x.x` (this will trigger the GitHub release workflow). -9. Wait for release workflow to complete. -10. Merge the pull request that was automatically opened by GitHub actions bot. -11. Notify about the release in IRS Matrix Chat using the following template: - - > **IRS Release x.x.x** - > - > IRS version x.x.x is released. - > - > https://github.com/eclipse-tractusx/item-relationship-service/releases/tag/x.x.x
- > https://github.com/eclipse-tractusx/item-relationship-service/releases/tag/item-relationship-service-y.y.y
- > **Full Changelog:** https://github.com/eclipse-tractusx/item-relationship-service/compare/w.w.w...x.x.x - - _(replace x.x.x with IRS version to release, y.y.y with IRS helm version to release and w.w.w with previous IRS version)_ - -#### Release chart only +4. Execute the workflow named _"Release IRS"_. The workflow takes three inputs. These are: + - IRS release version - type: semantic version string + - Helm Chart release version - type: semantic version string + - Whether to automatically update the Helm Chart changelog with the change + _"- Update IRS version to x.x.x"_. This is a checkbox which is ticked by default. +5. The workflow makes automated changes and creates a pull request from them right away. + Please review the created pull request within 15 minutes. If you fail to do so, or if the + pull request gets closed, the workflow will fail. +6. Once the pull request has been merged, the workflow continues execution. It pushes a tag (which will be + the semantic IRS release version number) and creates the release. Subsequent workflows, such + as the IRS build workflow, are triggered automatically. +7. Notify about the release in IRS Matrix Chat using the following template: + +> **IRS Release x.x.x** +> +> IRS version x.x.x is released. +> +> https://github.com/eclipse-tractusx/item-relationship-service/releases/tag/x.x.x
+> https://github.com/eclipse-tractusx/item-relationship-service/releases/tag/item-relationship-service-y.y.y
+> **Full Changelog:** https://github.com/eclipse-tractusx/item-relationship-service/compare/w.w.w...x.x.x + +_(replace x.x.x with IRS version to release, y.y.y with Helm Chart version to release and w.w.w with previous IRS +version)_ + +### Release Helm chart only 1. Choose a release version using [semantic versioning](https://semver.org/spec/v2.0.0.html) and create a corresponding branch according to the template: `chore/release-chart-x.x.x`. 2. Add new version to [charts/item-relationship-service/CHANGELOG.md](charts/item-relationship-service/CHANGELOG.md) -3. Change chart version in [Chart.yaml](charts/item-relationship-service/Chart.yaml) -4. Create pull request from [release preparation branch to main](https://github.com/eclipse-tractusx/item-relationship-service/compare/chore/release-chart-x.x.x) +3. Change chart version in [Chart.yaml](charts/item-relationship-service/Chart.yaml) +4. Create pull request + from [release preparation branch to main](https://github.com/eclipse-tractusx/item-relationship-service/compare/chore/release-chart-x.x.x) 5. Merge this pull request to main. 6. Wait for release workflow to complete. - ## Contact See [CONTACT](CONTACT.md) diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index ac3b68acd3..dbacbc087b 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -3043,4 +3043,4 @@ components: description: Api Key access in: header name: X-API-KEY - type: apiKey + type: apiKey \ No newline at end of file From 94c5f2c50be9887a1cc8385467dffa0a187d4a99 Mon Sep 17 00:00:00 2001 From: jhartmann Date: Fri, 12 Jul 2024 16:05:15 +0200 Subject: [PATCH 2/3] chore(release): revert workflow triggers --- .github/workflows/helm-chart-release.yaml | 12 +----------- .github/workflows/irs-build.yml | 19 +------------------ .github/workflows/swagger-editor-validate.yml | 13 +------------ .github/workflows/trivy-docker-hub-scan.yml | 8 -------- .github/workflows/trivy-image-scan.yml | 11 +---------- docs/src/api/irs-api.yaml | 2 +- 6 files changed, 5 insertions(+), 60 deletions(-) diff --git a/.github/workflows/helm-chart-release.yaml b/.github/workflows/helm-chart-release.yaml index 49d51cae90..529bdd3289 100644 --- a/.github/workflows/helm-chart-release.yaml +++ b/.github/workflows/helm-chart-release.yaml @@ -2,12 +2,6 @@ name: Release Helm Charts on: workflow_dispatch: # Trigger manually - workflow_call: - inputs: - ref-to-check-out: - description: 'Ref of branch/tag from which to execute workflow' - required: true - type: string push: branches: - main @@ -27,8 +21,6 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - fetch-tags: 'true' - ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Get helm charts latest tag version id: step1 @@ -44,7 +36,7 @@ jobs: echo "Exported $chartVersion helm charts version" release: - needs: [get-helm-charts-versions-irs] + needs: "get-helm-charts-versions-irs" if: needs.get-helm-charts-versions-irs.outputs.latest_version != needs.get-helm-charts-versions-irs.outputs.current_version # depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions # see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token @@ -56,8 +48,6 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - fetch-tags: 'true' - ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Configure Git run: | diff --git a/.github/workflows/irs-build.yml b/.github/workflows/irs-build.yml index 01069a91e9..e04ffd449e 100644 --- a/.github/workflows/irs-build.yml +++ b/.github/workflows/irs-build.yml @@ -2,13 +2,6 @@ name: IRS build on: workflow_dispatch: # Trigger manually - workflow_call: - inputs: - ref-to-check-out: - description: 'Ref of branch/tag from which to execute workflow' - required: true - type: string - pull_request: paths-ignore: - '**/*.md' @@ -33,9 +26,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - fetch-tags: 'true' - ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Set up JDK 17 uses: actions/setup-java@v4 @@ -76,9 +66,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 - fetch-tags: 'true' - ref: ${{ inputs.ref-to-check-out || github.ref }} + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of sonar analysis - name: Set up JDK 17 uses: actions/setup-java@v4 @@ -120,9 +108,6 @@ jobs: image-tag: ${{ steps.version.outputs.image_tag }} steps: - uses: actions/checkout@v4 - with: - fetch-tags: 'true' - ref: ${{ inputs.ref-to-check-out || github.ref }} # Needed to create multi-platform image - name: Set up Docker Buildx @@ -183,5 +168,3 @@ jobs: needs: - build_images uses: ./.github/workflows/trivy-docker-hub-scan.yml - with: - ref-to-check-out: ${{ inputs.ref-to-check-out || github.ref }} diff --git a/.github/workflows/swagger-editor-validate.yml b/.github/workflows/swagger-editor-validate.yml index 00af44cca5..efcecb035f 100644 --- a/.github/workflows/swagger-editor-validate.yml +++ b/.github/workflows/swagger-editor-validate.yml @@ -2,12 +2,6 @@ name: "Validate OpenAPI definition" on: workflow_dispatch: # Trigger manually - workflow_call: - inputs: - ref-to-check-out: - description: 'Ref of branch/tag from which to execute workflow' - required: true - type: string pull_request: push: branches: @@ -21,12 +15,7 @@ jobs: name: Swagger Editor Validator Remote steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-tags: 'true' - ref: ${{ inputs.ref-to-check-out || github.ref }} - + - uses: actions/checkout@v4 - name: Validate OpenAPI definition uses: char0n/swagger-editor-validate@v1 with: diff --git a/.github/workflows/trivy-docker-hub-scan.yml b/.github/workflows/trivy-docker-hub-scan.yml index 2619f38b70..00310d2adf 100644 --- a/.github/workflows/trivy-docker-hub-scan.yml +++ b/.github/workflows/trivy-docker-hub-scan.yml @@ -3,11 +3,6 @@ name: "Trivy vulnerability scanner for Docker Hub Image" on: workflow_dispatch: # Trigger manually workflow_call: # Trigger by another workflow - inputs: - ref-to-check-out: - description: 'Ref of branch/tag from which to execute workflow' - required: true - type: string schedule: - cron: "0 0 * * *" @@ -22,9 +17,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - fetch-tags: 'true' - ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master diff --git a/.github/workflows/trivy-image-scan.yml b/.github/workflows/trivy-image-scan.yml index 2bec2c5ee5..23699557cd 100644 --- a/.github/workflows/trivy-image-scan.yml +++ b/.github/workflows/trivy-image-scan.yml @@ -5,12 +5,6 @@ name: "Trivy vulnerability scanner for image" on: workflow_dispatch: # Trigger manually - workflow_call: - inputs: - ref-to-check-out: - description: 'Ref of branch/tag from which to execute workflow' - required: true - type: string pull_request: paths-ignore: - '**/*.md' @@ -41,11 +35,8 @@ jobs: - 5000:5000 steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v4 - with: - fetch-tags: 'true' - ref: ${{ inputs.ref-to-check-out || github.ref }} - name: Build image uses: docker/build-push-action@v6 diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index dbacbc087b..ac3b68acd3 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -3043,4 +3043,4 @@ components: description: Api Key access in: header name: X-API-KEY - type: apiKey \ No newline at end of file + type: apiKey From 8ac4af98797624404df9fdc8fab07191018882ee Mon Sep 17 00:00:00 2001 From: jhartmann Date: Fri, 12 Jul 2024 16:05:35 +0200 Subject: [PATCH 3/3] chore(release): switch back to pure documentation preparation for release --- .github/workflows/release.yaml | 127 ++++++--------------------------- CONTRIBUTING.md | 20 +++--- 2 files changed, 29 insertions(+), 118 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c46b919601..23c2b91e4a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: Release IRS +name: Prepare Release documentation on: workflow_dispatch: @@ -25,8 +25,7 @@ env: OPENAPI_SPEC_PATH: 'docs/src/api/irs-api.yaml' HELM_CHART_PATH: 'charts/item-relationship-service' SEMVER_PATTERN: '[0-9]+\.[0-9]+\.[0-9]+' - SEMVER_PATTERN_SED: '[0-9]\+\.[0-9]\+\.[0-9]\+\' - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SEMVER_PATTERN_SED: '[0-9]\+\.[0-9]\+\.[0-9]\+' jobs: release: @@ -47,9 +46,9 @@ jobs: - name: Validate that IRS and Helm Chart versions don't exist yet run: | # IRS version can be checked via git tag since every release has a tag - matched_irs_version=$(git tag | grep -Eo "${{ inputs.irs-version }}" || echo "") + matched_irs_version=$(git tag | grep -Eo "^${{ inputs.irs-version }}" || echo "") # extract from Helm Chart changelog - matched_helm_chart_version=$(grep -Eo "## \[${{ inputs.helm-chart-version }}\]" ${{ env.HELM_CHART_PATH }}/CHANGELOG.md || echo "") + matched_helm_chart_version=$(git tag | grep -Eo "^(irs-helm|item-relationship-service)-${{ inputs.irs-version }}" || echo "") if [[ -n "$matched_irs_version" || -n "$matched_helm_chart_version" ]]; then echo "At least one of the version numbers ${{ inputs.irs-version }} or ${{ inputs.helm-chart-version }} already exists." @@ -119,9 +118,8 @@ jobs: run: sed -i "s|${{ steps.main-changelog-update.outputs.previous-irs-version }}|${{ inputs.irs-version }}|" ${{ env.IRS_APPLICATION_PATH }} - name: Update irs-api.yaml - uses: mikefarah/yq@v4.44.2 - with: - cmd: yq -i eval '.info.version = "${{ inputs.irs-version }}"' ${{ env.OPENAPI_SPEC_PATH }} + run: | + sed -i '0,/version: ${{ env.SEMVER_PATTERN_SED }}/s//version: ${{ inputs.irs-version }}/' ${{ env.OPENAPI_SPEC_PATH }} - name: Update Chart.yaml appVersion uses: mikefarah/yq@v4.44.2 @@ -133,66 +131,6 @@ jobs: with: cmd: yq -i eval '.version = "${{ inputs.helm-chart-version }}"' ${{ env.HELM_CHART_PATH }}/Chart.yaml - - name: Update docs and Helm chart for release - id: cpr - uses: peter-evans/create-pull-request@v6 - with: - commit-message: 'chore(docs): updated docs and Helm chart for IRS release ${{ inputs.irs-version }}' - branch: action/update-for-release-${{ inputs.irs-version }} - delete-branch: true - title: "chore: updated docs and Helm chart for release" - body: This PR prepares the docs and the Helm chart for IRS release ${{ inputs.irs-version }}. - Please check whether everything was updated correctly. Once this PR is merged, the release process will continue automatically. - - - name: Wait for pull request merge - run: | - pull_request_number=${{ steps.cpr.outputs.pull-request-number }} - pull_request_merged="False" - seconds_waited_for_merge=0 - # set duration between api requests - sleep_interval_length=5 # seconds - timeout_in_minutes=15 - - echo "Waiting for merge of PR #$pull_request_number." - - while [[ "$pull_request_merged" == "False" ]] - do - # give some time to merge pull request - sleep "$sleep_interval_length"s - - # retrieve pr status using GH API's pull requests endpoint with GH CLI - pr_status=$(gh pr view $pull_request_number --json state --jq ".state") - - case $pr_status in - - MERGED) - pull_request_merged="True" - echo "PR #$pull_request_number merged, continuing the workflow." - ;; - - OPEN) - seconds_waited_for_merge=$((seconds_waited_for_merge+sleep_interval_length)) - - # abort workflow when having waited for more than allowed time - if [[ $seconds_waited_for_merge -gt $((timeout_in_minutes*60)) ]]; then - echo "Timeout waiting for merge of PR #$pull_request_number, aborting the workflow." - exit 1 - fi - ;; - - CLOSED) - echo "PR #$pull_request_number was closed, aborting the workflow." - exit 1 - ;; - - esac - - done - continue-on-error: false - - - name: Create and push new Git tag for release and pull latest changes - run: git tag ${{ inputs.irs-version }} && git push origin ${{ inputs.irs-version }} && git pull - - name: Extract changelog text # See: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings run: | @@ -203,43 +141,18 @@ jobs: /${{ steps.main-changelog-update.outputs.previous-irs-version }}...${{ inputs.irs-version }} >> $GITHUB_ENV echo "$EOF" >> "$GITHUB_ENV" - - name: Create IRS release - uses: softprops/action-gh-release@v2 + - name: Update docs and Helm chart for release + uses: peter-evans/create-pull-request@v6 with: - body: ${{ env.CHANGELOG }} - tag_name: ${{ inputs.irs-version }} - - release-helm-chart: - name: "Release Helm chart" - needs: - - release - uses: ./.github/workflows/helm-chart-release.yaml - with: - ref-to-check-out: 'refs/tags/${{ inputs.irs-version }}' - - build-irs: - name: "Build IRS" - needs: - - release - uses: ./.github/workflows/irs-build.yml - secrets: inherit - with: - ref-to-check-out: 'refs/tags/${{ inputs.irs-version }}' - - trivy-image-scan: - name: "Scan image in local registry with Trivy" - needs: - - release - uses: ./.github/workflows/trivy-image-scan.yml - secrets: inherit - with: - ref-to-check-out: 'refs/tags/${{ inputs.irs-version }}' - - validate-openapi-definition: - needs: - - release - name: "Validate OpenAPI definition" - uses: ./.github/workflows/swagger-editor-validate.yml - secrets: inherit - with: - ref-to-check-out: 'refs/tags/${{ inputs.irs-version }}' \ No newline at end of file + commit-message: 'chore(docs): updated docs and Helm chart for IRS release ${{ inputs.irs-version }}' + branch: action/update-for-release-${{ inputs.irs-version }} + delete-branch: true + title: "chore: updated docs and Helm chart for release" + body: This PR prepares the docs and the Helm chart for IRS release ${{ inputs.irs-version }}. + Please check whether everything was updated correctly. Once this PR is merged, you can draft a new release + with the following Releasenotes. + + ``` + ${{ env.CHANGELOG }} + + ``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 972e37eb02..297234ee64 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -212,24 +212,22 @@ https://github.com/google/google-java-format/blob/master/README.md#intellij-jre- 1. Choose a release version using [semantic versioning](https://semver.org/spec/v2.0.0.html) and create a corresponding branch according to the template: `chore/prepare-release-x.x.x`. -2. Add release notes for new version in [CHANGELOG.md](CHANGELOG.md) - and [charts/item-relationship-service/CHANGELOG.md](charts/item-relationship-service/CHANGELOG.md) - (for an example [see here](https://github.com/eclipse-tractusx/item-relationship-service/pull/429)) +2. Make sure the changelog entries [CHANGELOG.md](CHANGELOG.md) + and [charts/item-relationship-service/CHANGELOG.md](charts/item-relationship-service/CHANGELOG.md) are up-to-date - Check if the changelog entries for the release are complete. - Add the corresponding GitHub issue numbers to each entry if missing. 3. Update [COMPATIBILITY_MATRIX.md](COMPATIBILITY_MATRIX.md). -4. Execute the workflow named _"Release IRS"_. The workflow takes three inputs. These are: +4. Execute the workflow named _"Prepare Release documentation"_. The workflow takes three inputs. These are: - IRS release version - type: semantic version string - Helm Chart release version - type: semantic version string - Whether to automatically update the Helm Chart changelog with the change _"- Update IRS version to x.x.x"_. This is a checkbox which is ticked by default. -5. The workflow makes automated changes and creates a pull request from them right away. - Please review the created pull request within 15 minutes. If you fail to do so, or if the - pull request gets closed, the workflow will fail. -6. Once the pull request has been merged, the workflow continues execution. It pushes a tag (which will be - the semantic IRS release version number) and creates the release. Subsequent workflows, such - as the IRS build workflow, are triggered automatically. -7. Notify about the release in IRS Matrix Chat using the following template: +5. The workflow updates the necessary documentation and creates a pull request right away. + Review the changes and merge the PR. +6. Once the pull request has been merged, the helm chart will be release automatically. +7. To create the IRS release, [draft a new release](https://github.com/eclipse-tractusx/item-relationship-service/releases/new). As a tag and title, choose the IRS version provided to the release workflow. (If the release is created from a hotfix branch, make sure to choose this hotfix branch as the target of the tag) +8. Paste the release notes from the PR into the release description. +9. Notify about the release in IRS Matrix Chat using the following template: > **IRS Release x.x.x** >