Skip to content

Manually Release Chart #165

Manually Release Chart

Manually Release Chart #165

Workflow file for this run

name: Manually Release Chart
env:
MERGE_BRANCH: gh-pages
PR_LABEL: pr/release/robot_update_githubpage
PR_REVIWER: weizhoublue
DAOCLOUD_HARBOR_URL: https://release.daocloud.io
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
inputs:
project:
description: 'project name.[ leave empty for all projects]'
required: false
ref:
description: 'branch name, tag or sha'
required: true
default: main
daocloud:
description: 'enable push to daocloud repo'
required: true
type: boolean
default: true
workflow_call:
inputs:
project:
required: true
type: string
ref:
required: true
type: string
justpush:
required: true
type: string
permissions: write-all
jobs:
package:
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.get_ref.outputs.ref }}
steps:
- name: Get Ref
id: get_ref
run: |
if ${{ inputs.project != '' }} ; then
echo "trigger by workflow_call"
echo ::set-output name=project::${{ inputs.project }}
echo ::set-output name=release::true
echo ::set-output name=ref::${{ inputs.ref }}
echo ::set-output name=publishversion::true
elif ${{ github.event_name == 'workflow_dispatch' }} ; then
echo "call by self workflow_dispatch"
if ${{ github.event.inputs.project == '' }} ; then
echo ::set-output name=project::all
else
echo ::set-output name=project::${{ github.event.inputs.project }}
fi
# release to github pages
echo ::set-output name=release::${{ github.event.inputs.daocloud }}
echo ::set-output name=ref::${{ github.event.inputs.ref }}
echo ::set-output name=publishversion::false
elif ${{ github.event_name == 'push' }} ; then
echo "call by tag push"
echo ::set-output name=project::all
echo ::set-output name=release::true
# release to github pages
echo ::set-output name=ref::${GITHUB_REF##*/}
echo ::set-output name=publishversion::true
else
echo "unexpected event: ${{ github.event_name }}"
exit 1
fi
# some event, the tag is not sha, so checkout it and get sha
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: false
ref: ${{ steps.get_ref.outputs.ref }}
- name: Result Ref
id: result
run: |
ref=$( git show -s --format='format:%H')
echo ::set-output name=ref::${ref}
- name: Set up Helm
uses: azure/[email protected]
- name: package chart
id: package
run: |
ROOT_DIR=`pwd`
project_list="${{ steps.get_ref.outputs.project }}"
if [ "$project_list" == "all" ] || [ -z "$project_list" ] ; then
project_list=""
TMP=`ls charts`
for ITEM in $TMP ; do
if [ -d "${ROOT_DIR}/charts/${ITEM}/${ITEM}" ] ; then
project_list+=" $ITEM "
fi
done
fi
mkdir _upload
cd _upload
for ITEM in $project_list ; do
[ ! -d "${ROOT_DIR}/charts/${ITEM}/${ITEM}" ] && echo "error, failed to find project $ITEM in /charts" && exit 1
helm package ${ROOT_DIR}/charts/${ITEM}/${ITEM}
echo "package ${ITEM}"
done
echo "---------finish--------"
ls
echo ::set-output name=project_list::${project_list}
- name: Upload chart artifact
uses: actions/[email protected]
with:
name: charts
path: _upload
retention-days: 1
- name: Install helm-push
if: ${{ steps.get_ref.outputs.release == 'true' }}
run: |
helm plugin install https://github.com/chartmuseum/helm-push
- name: push to daocloud
if: ${{ steps.get_ref.outputs.release == 'true' }}
run: |
ROOT_DIR=`pwd`
cd _upload
set -x
RETRY_NUMBER=100
FAILED_CHART=""
SUCCEED_CHART=""
for ITEM in ${{ steps.package.outputs.project_list }} ; do
DAO_PROJECT=` grep "DAOCLOUD_REPO_PROJECT" ${ROOT_DIR}/charts/${ITEM}/config | awk -F= '{print $2}' | tr -d ' ' `
[ -z "$DAO_PROJECT" ] && echo "error, failed to find DAOCLOUD_REPO_PROJECT config in charts/${ITEM}/config " && exit 1
CHART_FILE=` ls | grep -o -E "^${ITEM}-[v0-9]+.[0-9]+.[0-9]+.*.tgz" `
[ ! -f "${CHART_FILE}" ] && echo "error, failed to find chart.tgz for $ITEM " && ls && exit 2
DAO_ADDRESS=${{ env.DAOCLOUD_HARBOR_URL }}/chartrepo/${DAO_PROJECT}
echo "push $CHART_FILE to $DAO_ADDRESS "
BAD=true
for ((N=0;N<RETRY_NUMBER;N++)); do
helm repo add daocloud-${DAO_PROJECT} ${DAO_ADDRESS} --username=${{ secrets.DAOCLOUD_HARBOR_USER }} --password=${{ secrets.DAOCLOUD_HARBOR_PASSWORD }} || { sleep 2 ; continue ; }
BAD="" && break
done
if [ "$BAD" != "true" ] ; then
BAD=true
for ((N=0;N<RETRY_NUMBER;N++)); do
helm cm-push ${CHART_FILE} daocloud-${DAO_PROJECT} --username=${{ secrets.DAOCLOUD_HARBOR_USER }} --password=${{ secrets.DAOCLOUD_HARBOR_PASSWORD }} || { sleep 2 ; continue ; }
BAD="" && break
done
fi
if [ "$BAD" == "true" ] ; then
echo "error, failed to helm push ${CHART_FILE} "
FAILED_CHART+=" ${CHART_FILE} "
else
echo "succeeded to helm push ${CHART_FILE} "
SUCCEED_CHART+=" ${CHART_FILE} "
fi
done
echo "============== result =========="
echo "SUCCEED_CHART: ${SUCCEED_CHART}"
echo ""
echo "FAILED_CHART: ${FAILED_CHART}"
if [ -n "$FAILED_CHART" ]; then
exit 1
fi
exit 0
#- name: Create Release
# id: create_release
# if: ${{ steps.get_ref.outputs.publishversion == 'true' }}
# uses: ncipollo/[email protected]
# with:
# artifacts: "_upload/*"
# allowUpdates: true
# removeArtifacts: true
# replacesArtifacts: true
# artifactErrorsFailBuild: true
# token: ${{ secrets.GITHUB_TOKEN }}
# tag: ${{ steps.get_ref.outputs.ref }}
# name: "Release ${{ steps.get_ref.outputs.ref }}"
# update /index.yaml in the target branch
update_githubpage:
runs-on: ubuntu-latest
needs: [package]
if: ${{ inputs.justpush != 'true' }}
steps:
- name: Get Base Chart URL
id: get_base_url
run: |
name=${{ github.repository }}
proj=${name#*/}
url=https://${{ github.repository_owner }}.github.io/${proj}
echo "::set-output name=url::${url}"
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ env.MERGE_BRANCH }}
persist-credentials: "true"
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: charts
path: ./
- name: Update Chart Yaml
run: |
ls
helm repo index ./ --url ${{ steps.get_base_url.outputs.url }}
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
title: "robot Update chart to branch ${{ env.MERGE_BRANCH }} "
commit-message: "robot Update chart from ${{ needs.package.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} "
branch-suffix: timestamp
branch: robot/update_chart
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
signoff: true
token: ${{ secrets.WELAN_PAT }}
labels: ${{ env.PR_LABEL }}
reviewers: ${{ env.PR_REVIWER }}