Skip to content

Update chart version to 0.6.0 (#115) #31

Update chart version to 0.6.0 (#115)

Update chart version to 0.6.0 (#115) #31

Workflow file for this run

name: GoRelease
on:
push:
tags:
- 'v*.*.*'
env:
# Common versions
GO_VERSION: '1.21'
GO_REQUIRED_MIN_VERSION: ''
GITHUB_REF: ${{ github.ref }}
CHART_NAME: managed-serviceaccount
CHART_VERSION_FILE_PATH: ./charts/managed-serviceaccount/Chart.yaml
jobs:
env:
name: prepare release env
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: get release version
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: get major release version
run: |
echo "MAJOR_RELEASE_VERSION=${RELEASE_VERSION%.*}" >> $GITHUB_ENV
echo "TRIMMED_RELEASE_VERSION=${RELEASE_VERSION#v}" >> $GITHUB_ENV
outputs:
MAJOR_RELEASE_VERSION: ${{ env.MAJOR_RELEASE_VERSION }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
TRIMMED_RELEASE_VERSION: ${{ env.TRIMMED_RELEASE_VERSION }}
images:
name: images
runs-on: ubuntu-latest
needs: [ env ]
strategy:
matrix:
arch: [ amd64, arm64 ]
steps:
- name: checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: install Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: install imagebuilder
run: go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.3
- name: pull base image
run: docker pull registry.access.redhat.com/ubi8/ubi-minimal:latest --platform=linux/${{ matrix.arch }}
- name: images
run: |
IMAGE_TAG=${{ needs.env.outputs.RELEASE_VERSION }}-${{ matrix.arch }} \
IMAGE_BUILD_EXTRA_FLAGS="--build-arg OS=linux --build-arg ARCH=${{ matrix.arch }}" \
make images
- name: push
run: |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
docker push quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }}-${{ matrix.arch }}
image-manifest:
name: image manifest
runs-on: ubuntu-latest
needs: [ env, images ]
steps:
- name: checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: create
run: |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
docker manifest create quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }} \
quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }}-amd64 \
quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }}-arm64
- name: annotate
run: |
docker manifest annotate quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }} \
quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }}-amd64 --arch amd64
docker manifest annotate quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }} \
quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }}-arm64 --arch arm64
- name: push
run: |
docker manifest push quay.io/open-cluster-management/managed-serviceaccount:${{ needs.env.outputs.RELEASE_VERSION }}
release:
name: release
runs-on: ubuntu-latest
needs: [ env, image-manifest ]
steps:
- name: checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: setup helm
uses: azure/setup-helm@v1
- name: chart package
run: |
mkdir -p release
pushd release
helm package ../charts/${{ env.CHART_NAME }}/
popd
- name: generate changelog
run: |
echo "# Managed ServiceAccount ${{ needs.env.outputs.RELEASE_VERSION }}" > /home/runner/work/changelog.txt
- name: publish release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body_path: /home/runner/work/changelog.txt
files: |
release/*.tgz
draft: true
prerelease: false
generate_release_notes: true
- name: submit charts to OCM chart repo
uses: actions/github-script@v6
with:
github-token: ${{ secrets.OCM_BOT_PAT }}
script: |
try {
const result = await github.rest.actions.createWorkflowDispatch({
owner: 'open-cluster-management-io',
repo: 'helm-charts',
workflow_id: 'download-chart.yml',
ref: 'main',
inputs: {
repo: "${{ github.repository }}",
version: "${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }}",
"chart-name": "${{ env.CHART_NAME }}",
},
})
console.log(result);
} catch(error) {
console.error(error);
core.setFailed(error);
}
increase-chart-version:
runs-on: ubuntu-latest
needs: [ env, release ]
steps:
- name: checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: calculate next version
id: calculate_next_version
run: |
echo "Current version: $CURRENT_VERSION"
# Extract the major and minor version components
MAJOR=$(echo $CURRENT_VERSION | cut -d '.' -f 1)
MINOR=$(echo $CURRENT_VERSION | cut -d '.' -f 2)
# Increment the minor version
NEXT_MINOR=$((MINOR + 1))
# Construct the next version
NEXT_VERSION="$MAJOR.$NEXT_MINOR.0"
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
env:
CURRENT_VERSION: ${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }}
- name: update chart version file
id: update_chart_version
run: |
echo "Updating chart version file from $CURRENT_VERSION to $NEXT_VERSION"
sed -i "s/version: $CURRENT_VERSION/version: $NEXT_VERSION/" ${{ env.CHART_VERSION_FILE_PATH }}
git diff
FILE_CHANGED=$(git diff --exit-code --quiet && echo false || echo true)
echo "Chart version file changed: $FILE_CHANGED"
echo "file_changed=$FILE_CHANGED" >> $GITHUB_OUTPUT
env:
CURRENT_VERSION: ${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }}
NEXT_VERSION: ${{ steps.calculate_next_version.outputs.next_version }}
- name: check if pull request already exists
id: check_pull_request
if : steps.update_chart_version.outputs.file_changed == 'true'
run: |
gh pr list --state open > pr_list.txt
cat pr_list.txt
PR_EXIST=$(grep -q "Update chart version to ${{ steps.calculate_next_version.outputs.next_version }}" pr_list.txt && echo true || echo false)
echo "pr_exists=$PR_EXIST" >> $GITHUB_OUTPUT
echo "Pull request for version ${{ steps.calculate_next_version.outputs.next_version }} exists: $PR_EXIST"
rm -rf pr_list.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: create pull request
if: steps.update_chart_version.outputs.file_changed == 'true' && steps.check_pull_request.outputs.pr_exists != 'true'
uses: peter-evans/create-pull-request@v6
with:
# use OCM bot token to bypass "GitHub Actions is not permitted to create or approve pull requests."
token: ${{ secrets.OCM_BOT_PAT }}
commit-message: |
Update chart version to ${{ steps.calculate_next_version.outputs.next_version }}
title: ":seedling: Update chart version to ${{ steps.calculate_next_version.outputs.next_version }}"
body: "Automatically updating chart version to ${{ steps.calculate_next_version.outputs.next_version }}"
branch: update-chart-version-${{ steps.calculate_next_version.outputs.next_version }}
signoff: true
base: main
env:
CURRENT_VERSION: ${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }}
NEXT_VERSION: ${{ steps.calculate_next_version.outputs.next_version }}