diff --git a/.github/workflows/create-tag-release.yaml b/.github/workflows/create-tag-release.yaml new file mode 100644 index 00000000..d6227d94 --- /dev/null +++ b/.github/workflows/create-tag-release.yaml @@ -0,0 +1,73 @@ +# Copyright (c) 2025 Dell Inc., or its subsidiaries. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 + +# This workflow is used to create Github Tag and Release +name: Create Tag and Release +# Invocable as a reusable workflow +on: + workflow_call: + inputs: + version: + description: "Semantic version to release. Ex: major, minor, or patch" + type: string + required: true + images: + description: "List of image names. Example: csi-powerstore,csi-isilon" + type: string + required: true + +jobs: + build-and-scan: + name: Build and Scan + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.24" + + - name: Install dependencies + run: go mod tidy + + - name: Build binaries + run: | + echo "Building binaries to attach to the release if any..." + if "${{ inputs.images == 'cert-csi' }}"; then + make build + mv cert-csi cert-csi-linux-amd64 + echo "BIN_NAME=cert-csi-linux-amd64" >> $GITHUB_ENV + fi + if "${{ contains(inputs.images, 'dell-csi-replicator') || contains(inputs.images, 'dell-replication-controller') }}"; then + cd repctl + make build + mv repctl repctl-linux-amd64 + mv repctl-linux-amd64 ../ + echo "BIN_NAME=repctl-linux-amd64" >> $GITHUB_ENV + fi + + - name: Upload Binaries + if: ${{ env.BIN_NAME != '' }} + uses: actions/upload-artifact@v4.6.1 + env: + BIN_NAME: ${{ env.BIN_NAME }} + with: + name: ${{ env.BIN_NAME }} + path: ${{ env.BIN_NAME }} + + release-and-tag: + name: Tag and Release + needs: build-and-scan + uses: dell/common-github-actions/.github/workflows/release-creator.yaml@main + with: + version: ${{ inputs.version }} + secrets: inherit diff --git a/.github/workflows/release-image.yaml b/.github/workflows/release-image.yaml new file mode 100644 index 00000000..93feae6f --- /dev/null +++ b/.github/workflows/release-image.yaml @@ -0,0 +1,72 @@ +# Copyright (c) 2025 Dell Inc., or its subsidiaries. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 + +# This workflow is used to push images to quay.io +name: Release Image + +# Invocable as a reusable workflow +on: + workflow_call: + inputs: + version: + description: "Semantic version to release. Ex: major, minor, or patch" + type: string + required: true + images: + description: "List of image names. Example: csi-powerstore,csi-isilon" + type: string + required: true + +jobs: + push-images: + if: ${{ inputs.version == 'patch' || inputs.version == 'minor' || inputs.version == 'major' }} + name: Release images to Quay + runs-on: ubuntu-latest + steps: + - name: Push images to Quay.io + shell: bash + run: | + images_list=$(echo '${{ inputs.images }}' | tr -d '[]"' | tr ',' ' ') + REPOSITORY="delltech/csm" + + for image in $images_list; do + latest_version=$(curl -s https://quay.io/api/v1/repository/$REPOSITORY/$image/tag/?limit=100 | jq -r '.tags[].name' | sort -V | tail -n 1) + echo "Current latest version of $image:$latest_version" + + IFS='.' read -r -a version_parts <<< "$latest_version" + + if "${{ inputs.version == 'major' }}"; then + version_parts[0]=$(expr ${version_parts[0]} + 1) + new_version="${version_parts[0]}.0.0" + fi + if "${{ inputs.version == 'minor' }}"; then + version_parts[1]=$(expr ${version_parts[1]} + 1) + new_version="${version_parts[0]}.${version_parts[1]}.0" + fi + if "${{ inputs.version == 'patch' }}"; then + version_parts[2]=$(expr ${version_parts[2]} + 1) + new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}" + fi + + SHA=$(curl -s --location --request GET https://quay.io/api/v1/repository/$REPOSITORY/$image/tag?specificTag=nightly --header 'Content-Type: application/json' --header 'Authorization: Bearer ${{ secrets.QUAY_API_TOKEN }}' | jq -r '.tags[0].manifest_digest') + echo "Pushing image: $image:$new_version" + + curl --location --request PUT https://quay.io/api/v1/repository/$REPOSITORY/$image/tag/$new_version \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Bearer ${{ secrets.QUAY_API_TOKEN }}' \ + --data-raw '{ + "manifest_digest": "'"$SHA"'" + }' + + curl --location --request PUT https://quay.io/api/v1/repository/$REPOSITORY/$image/tag/latest \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Bearer ${{ secrets.QUAY_API_TOKEN }}' \ + --data-raw '{ + "manifest_digest": "'"$SHA"'" + }' + done diff --git a/README.md b/README.md index 1cf91fd7..f8bbe4df 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,150 @@ jobs: name: Check License Header uses: dell/common-github-actions/.github/workflows/check-license-header.yaml@main ``` +### create-tag-release + +This workflow automates the creation of Tag and Release in driver and module Github repositories. The workflow accepts two parameters as version and image, and can be used from any repo by creating a workflow that resembles the following. + +For manual trigger from driver and module repositories, here is the example for the csi-powerscale repo: + +```yaml +name: Create Tag and Release +# Invocable as a reusable workflow +# Can be manually triggered +on: # yamllint disable-line rule:truthy + workflow_call: + workflow_dispatch: + inputs: + option: + description: 'Select version to release' + required: true + type: choice + default: 'minor' + options: + - major + - minor + - patch + - n-1/n-2 patch (Provide input in the below box) + version: + description: "Patch version to release. example: 2.1.x (Use this only if n-1/n-2 patch is selected)" + required: false + type: string + repository_dispatch: + types: [auto-release-workflow] + +jobs: + process-inputs: + name: Process Inputs + runs-on: ubuntu-latest + outputs: + processedVersion: ${{ steps.set-version.outputs.versionEnv }} + steps: + - name: Process input + id: set-version + shell: bash + run: | + echo "Triggered by: ${{ github.event_name }}" + if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then + echo "versionEnv=minor" >> $GITHUB_OUTPUT + exit 0 + fi + if [[ "${{ github.event.inputs.version }}" != "" && "${{ github.event.inputs.option }}" == "n-1/n-2 patch (Provide input in the below box)" ]]; then + echo "versionEnv=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT + exit 0 + fi + if [[ "${{ github.event.inputs.option }}" != "n-1/n-2 patch (Provide input in the below box)" ]]; then + echo "versionEnv=${{ github.event.inputs.option }}" >> $GITHUB_OUTPUT + exit 0 + fi + echo "versionEnv=minor" >> $GITHUB_OUTPUT + + csm-release: + needs: process-inputs + uses: dell/common-github-actions/.github/workflows/create-tag-release.yaml@main + name: Create Tag and Release + with: + version: ${{ needs.process-inputs.outputs.processedVersion }} + images: 'csi-isilon' + secrets: inherit + + next-steps: + name: 📌 Next Steps for Release Process + runs-on: ubuntu-latest + needs: csm-release + steps: + - name: Share next steps with user + run: | + echo "✅ Tag and release completed." + echo "➡️ Please manually trigger the Jenkins image build job: CSM-Images-Build-Nightly." + echo "🚀 Once the Jenkins image build job is successful, trigger the Release Image workflow from GitHub Actions." +``` +### release-image + +This workflow automates releasing the images to quay.io. The workflow accepts two parameters as version and image, and can be used from any repo by creating a workflow that resembles the following. + +Before manually triggering this workflow from a driver or module repository, ensure that the create-tag-and-image workflow has been executed, followed by a manual trigger of the Jenkins job 'CSM-Images-Build-Nightly'. Once the Jenkins image build job is successful, the release-image workflow can be manually triggered to publish the image to quay.io. here is the example for the csi-powerscale repo: + +```yaml +name: Release CSI-Powerscale Image +# Invocable as a reusable workflow +# Can be manually triggered +on: # yamllint disable-line rule:truthy + workflow_call: + workflow_dispatch: + inputs: + option: + description: 'Select version to release' + required: true + type: choice + default: 'minor' + options: + - major + - minor + - patch + - n-1/n-2 patch (Provide input in the below box) + version: + description: "Patch version to release. example: 2.1.x (Use this only if n-1/n-2 patch is selected)" + required: false + type: string + repository_dispatch: + types: [auto-release-workflow] +jobs: + process-inputs: + name: Process Inputs + runs-on: ubuntu-latest + outputs: + processedVersion: ${{ steps.set-version.outputs.versionEnv }} + steps: + - name: Process input + id: set-version + shell: bash + run: | + echo "Triggered by: ${{ github.event_name }}" + if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then + echo "versionEnv=minor" >> $GITHUB_OUTPUT + exit 0 + fi + if [[ "${{ github.event.inputs.version }}" != "" && "${{ github.event.inputs.option }}" == "n-1/n-2 patch (Provide input in the below box)" ]]; then + # if both version and option are provided, then version takes precedence i.e. patch release for n-1/n-2 + echo "versionEnv=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT + exit 0 + fi + if [[ "${{ github.event.inputs.option }}" != "n-1/n-2 patch (Provide input in the below box)" ]]; then + # if only option is provided, then option takes precedence i.e. minor, major or patch release + echo "versionEnv=${{ github.event.inputs.option }}" >> $GITHUB_OUTPUT + exit 0 + fi + # if neither option nor version is provided, then minor release is taken by default (Auto-release) + echo "versionEnv=minor" >> $GITHUB_OUTPUT + csm-release: + needs: [process-inputs] + uses: dell/common-github-actions/.github/workflows/release-image.yaml@main + name: Release Image + with: + version: ${{ needs.process-inputs.outputs.processedVersion }} + images: 'csi-isilon' + secrets: inherit +``` ### csm-release-driver-module