From 761fd09c66e4ab33f69b6d34f0119a90d8e0186d Mon Sep 17 00:00:00 2001 From: cyclinder Date: Mon, 16 Oct 2023 10:17:18 +0800 Subject: [PATCH 1/2] e2e can be run on main branch --- .github/workflows/e2e.yaml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 5545c7c..a750065 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -1,4 +1,4 @@ -name: pull-request-e2e +name: e2e env: ONLINE_REGISTER: ghcr.io @@ -10,10 +10,14 @@ on: - opened - synchronize - reopened + push: + branches: + - main jobs: call-build-pr: uses: ./.github/workflows/call-image-build.yaml + if: ${{ github.event_name == 'pull_request_target' }} with: ref: ${{ github.ref }} tag: ${{ github.event.pull_request.head.sha }} @@ -21,9 +25,19 @@ jobs: ci: true secrets: inherit + call-build-main: + uses: ./.github/workflows/call-image-build.yaml + if: ${{ github.event_name == 'push' }} + with: + ref: ${{ github.ref }} + tag: ${{ github.sha }} + push: false + ci: true + secrets: inherit + call_e2e: runs-on: ubuntu-latest - needs: [call-build-pr] + needs: [call-build-pr,call-build-main] steps: - name: Checkout Code uses: actions/checkout@v3 From fc9e036c01fa305d7309c3299f1f7bf96bfbc555 Mon Sep 17 00:00:00 2001 From: cyclinder Date: Tue, 17 Oct 2023 14:50:00 +0800 Subject: [PATCH 2/2] CI: auto release helm chart --- .github/workflows/call-release-chart.yaml | 79 +++++++++++++++++++++++ .github/workflows/e2e.yaml | 29 ++++++--- 2 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/call-release-chart.yaml diff --git a/.github/workflows/call-release-chart.yaml b/.github/workflows/call-release-chart.yaml new file mode 100644 index 0000000..d253684 --- /dev/null +++ b/.github/workflows/call-release-chart.yaml @@ -0,0 +1,79 @@ +name: Call Release Charts + +env: + HELM_VERSION: v3.10.1 + +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+ + workflow_dispatch: + inputs: + ref: + description: 'tag, sha, branch' + required: true + default: v1.0.0 + +permissions: write-all + +jobs: + chart-release: + name: Create Chart Release + runs-on: ubuntu-latest + permissions: + contents: write + steps: + steps: + - name: Get Original Ref + id: get_original_ref + run: | + if ${{ github.event_name == 'workflow_dispatch' }} ; then + echo "call by workflow_dispatch" + ver=${{ inputs.ref }} + echo "ref=${ver}" >> $GITHUB_OUTPUT + elif ${{ github.event_name == 'push' }} ; then + echo "call by push" + ver=${{ github.ref }} + echo "ref=${ver}" >> $GITHUB_OUTPUT + else + echo "unexpected event: ${{ github.event_name }}" + exit 1 + fi + + - name: Checkout + uses: actions/checkout@v2 + with: + # Fetch entire history. Required for chart-releaser; see https://github.com/helm/chart-releaser-action/issues/13#issuecomment-602063896 + fetch-depth: 0 + ref: ${{ needs.get_original_ref.outputs.ref }} + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Chart releaser + run: | + # Download chart releaser + curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/v1.4.1/chart-releaser_1.4.1_linux_amd64.tar.gz" + tar -xzf cr.tar.gz + rm -f cr.tar.gz + repo=$(basename "$GITHUB_REPOSITORY") + owner=$(dirname "$GITHUB_REPOSITORY") + tag="${GITHUB_REF_NAME:1}" + echo "Creating release..." + # package chart + ./cr package charts/cilium-chaining + # upload chart to github releases + ./cr upload \ + --owner "$owner" \ + --git-repo "$repo" \ + --release-name-template "{{ .Name }}-chart-{{ .Version }}" \ + --token "${{ secrets.GITHUB_TOKEN }}" + # Update index and push to github pages + ./cr index \ + --owner "$owner" \ + --git-repo "$repo" \ + --index-path index.yaml \ + --release-name-template "{{ .Name }}-chart-{{ .Version }}" \ + --push diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index a750065..1388bf1 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -15,15 +15,24 @@ on: - main jobs: - call-build-pr: - uses: ./.github/workflows/call-image-build.yaml - if: ${{ github.event_name == 'pull_request_target' }} - with: - ref: ${{ github.ref }} - tag: ${{ github.event.pull_request.head.sha }} - push: false - ci: true - secrets: inherit + get_ref: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.get_ref.outputs.tag }} + steps: + - name: Get Ref + id: get_ref + run: | + if ${{ github.event_name == 'push' }} ; then + echo "trigger by push" + echo ::set-output name=tag::${{ github.sha }} + elif ${{ github.event_name == 'pull_request' }} ; then + echo "trigger by pull_request" + echo ::set-output name=tag::${{ github.event.pull_request.head.sha }} + else + echo "unexpected event: ${{ github.event_name }} " + exit 1 + fi call-build-main: uses: ./.github/workflows/call-image-build.yaml @@ -37,7 +46,7 @@ jobs: call_e2e: runs-on: ubuntu-latest - needs: [call-build-pr,call-build-main] + needs: [get_ref,call-build-image] steps: - name: Checkout Code uses: actions/checkout@v3