From aec5f82576fab78cfaf1c7eb1c6b959d6e5811e6 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Wed, 6 Mar 2024 13:13:55 -0700 Subject: [PATCH 1/6] Remove sync job from daily.yaml workflow --- .github/workflows/daily.yaml | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/.github/workflows/daily.yaml b/.github/workflows/daily.yaml index 340f19473b..7f071f1e09 100644 --- a/.github/workflows/daily.yaml +++ b/.github/workflows/daily.yaml @@ -8,34 +8,6 @@ on: # - main-source jobs: - sync: #this job should run first - runs-on: ubuntu-latest - steps: - - name: Checkout main-source branch - uses: actions/checkout@v3 - with: - ref: main-source # branch you want to sync - repository: marcosbc/partner-charts # your forked repository URL - - name: Configure Git - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - - name: Fetch upstream changes for main-source branch - run: | - git remote add upstream https://github.com/rancher/partner-charts.git # URL of upstream repository - git fetch upstream main-source - - name: Merge upstream changes into main-source branch - run: | - git checkout main-source - git merge upstream/main-source --allow-unrelated-histories --no-edit - git push origin main-source - - name: Merge upstream changes into main branch - run: | - git fetch upstream main # this fetch is necessary here - git checkout main - git merge upstream/main --allow-unrelated-histories --no-edit - git push origin main - build: needs: sync #this job should run after "sync" job runs-on: ubuntu-latest From e0fbd8f266db2274cd9340e55be99aa3a11a3aa0 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Wed, 6 Mar 2024 13:33:40 -0700 Subject: [PATCH 2/6] Introduce automation to release partner charts daily --- .github/workflows/daily.yaml | 43 ---------------------------------- .github/workflows/release.yaml | 32 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 43 deletions(-) delete mode 100644 .github/workflows/daily.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/daily.yaml b/.github/workflows/daily.yaml deleted file mode 100644 index 7f071f1e09..0000000000 --- a/.github/workflows/daily.yaml +++ /dev/null @@ -1,43 +0,0 @@ -# Authors: Samuel Attwood, Nefi Munoz -name: Partner Charts CI - -on: - workflow_dispatch: -# push: -# branches: -# - main-source - -jobs: - build: - needs: sync #this job should run after "sync" job - runs-on: ubuntu-latest - steps: - - name: Checkout main-source branch - uses: actions/checkout@v3 - - - name: Setup go - uses: actions/setup-go@v3 - with: - go-version: '>=1.17.0' - - - name: Run CI - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git config --global pull.rebase false # merge (this is the default) - scripts/pull-ci-scripts - bin/partner-charts-ci auto - git pull origin main-source - git push origin main-source - - name: Update main branch - run: | - # checkout action is only going to fetch the current branch, so "git checkout main" would fail if we don’t fetch main first - git fetch origin main --depth 1 - git checkout main - rm -r assets index.yaml - git checkout main-source -- index.yaml assets - - name: Auto commit & push - # Defaults pushing to current branch (main) - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: "Release Partner Charts" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..8eae513c60 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,32 @@ +name: Release Partner Charts + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * *' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Configure git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + - name: Update main-source branch + run: | + scripts/pull-ci-scripts + bin/partner-charts-ci auto + git push origin main-source + + - name: Update main branch + run: | + # checkout action only fetches main-source, so we need to fetch main branch also + git fetch origin main --depth 1 + git checkout main + git checkout main-source -- index.yaml assets + git commit -m "Release partner charts" + git push origin main From 842be8e969a13124f056a6b2edd8c386a00d09c6 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Thu, 7 Mar 2024 10:23:08 -0700 Subject: [PATCH 3/6] Remove sync-fork.yml workflow --- .github/workflows/sync-fork.yml | 48 --------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 .github/workflows/sync-fork.yml diff --git a/.github/workflows/sync-fork.yml b/.github/workflows/sync-fork.yml deleted file mode 100644 index bb34baa355..0000000000 --- a/.github/workflows/sync-fork.yml +++ /dev/null @@ -1,48 +0,0 @@ -#Author: Nefi Munoz -name: Sync Fork - -on: -# schedule: - # Runs every day at midnight UTC -# - cron: '0 0 * * *' - workflow_dispatch: - -jobs: - sync: - runs-on: ubuntu-latest - steps: - - name: Checkout main-source branch - uses: actions/checkout@v3 - with: - ref: main-source # branch you want to sync - repository: marcosbc/partner-charts # your forked repository URL - - name: Configure Git - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - - name: Fetch upstream changes for main-source branch - run: | - git remote add upstream https://github.com/rancher/partner-charts.git # URL of upstream repository - git fetch upstream main-source - - name: Merge upstream changes into main-source branch - run: | - git checkout main-source - git merge upstream/main-source --allow-unrelated-histories --no-edit - git push origin main-source - # - name: Checkout main branch - # uses: actions/checkout@v3 - # with: - # ref: main # branch you want to sync - # repository: marcosbc/partner-charts # your forked repository URL - # - name: Fetch upstream changes for main branch - # run: | - # git remote add upstream https://github.com/rancher/partner-charts.git # URL of upstream repository - # git fetch upstream main - - name: Merge upstream changes into main branch - run: | - git fetch upstream main # this fetch is necessary here - git checkout main - git merge upstream/main --allow-unrelated-histories --no-edit - git push origin main - - From 33fdb4269946242df2f81a6e6445ce5d99ead0f5 Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Fri, 8 Mar 2024 15:05:30 -0700 Subject: [PATCH 4/6] Submit PR instead of merging directly to main --- .github/workflows/update-main-source.yml | 41 +++++++++++++++++++ .../{release.yaml => update-main.yml} | 28 ++++++------- 2 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/update-main-source.yml rename .github/workflows/{release.yaml => update-main.yml} (50%) diff --git a/.github/workflows/update-main-source.yml b/.github/workflows/update-main-source.yml new file mode 100644 index 0000000000..a40203388c --- /dev/null +++ b/.github/workflows/update-main-source.yml @@ -0,0 +1,41 @@ +name: Auto-update charts + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * *' + +jobs: + update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Configure git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + - name: Update main-source branch + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_WORKFLOW: ${{ github.workflow }} + GITHUB_REPOSITORY: ${{ github.repository }} + run: | + scripts/pull-ci-scripts + BRANCH="auto-update/$(date '+%s')" + git checkout -b "$BRANCH" + bin/partner-charts-ci auto + + # exit if there are no changes + git diff --quiet main-source "$BRANCH" && exit 0 + + # close all existing PRs from branches starting with "auto-update" + gh pr --repo "$GITHUB_REPOSITORY" list --search 'head:auto-update' --json 'headRefName' --jq '.[] | join("\n")' | \ + xargs -n 1 gh pr --repo "$GITHUB_REPOSITORY" close + + # push changes + git push --set-upstream origin "$BRANCH" + TITLE="Auto-update charts on main-source" + BODY="This PR was created by the \"$GITHUB_WORKFLOW\" workflow. It auto-updates the helm charts on the main-source branch." + gh pr create --repo "$GITHUB_REPOSITORY" --base main-source --head "$BRANCH" --title "$TITLE" --body "$BODY" diff --git a/.github/workflows/release.yaml b/.github/workflows/update-main.yml similarity index 50% rename from .github/workflows/release.yaml rename to .github/workflows/update-main.yml index 8eae513c60..32f22df569 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/update-main.yml @@ -1,12 +1,13 @@ -name: Release Partner Charts +name: Update main branch from main-source on: workflow_dispatch: - schedule: - - cron: '0 0 * * *' + push: + branches: + - main-source jobs: - release: + update: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -16,17 +17,14 @@ jobs: git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - - name: Update main-source branch + - name: Update main branch with latest from main-source run: | - scripts/pull-ci-scripts - bin/partner-charts-ci auto - git push origin main-source - - - name: Update main branch - run: | - # checkout action only fetches main-source, so we need to fetch main branch also + # checkout action only fetches main-source, so we need to fetch main git fetch origin main --depth 1 git checkout main - git checkout main-source -- index.yaml assets - git commit -m "Release partner charts" - git push origin main + git rm -r assets index.yaml + git checkout main-source -- assets index.yaml + # exit if there are no changes + git diff-index --quiet HEAD assets index.yaml && exit 0 + git commit -m "Update partner charts" + git push origin From 2367f1f7d0713b6dd2818bb86d5abf01dd77603f Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Fri, 8 Mar 2024 20:07:32 -0700 Subject: [PATCH 5/6] Add [AUTOMATED] to PR title as requested --- .github/workflows/update-main-source.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-main-source.yml b/.github/workflows/update-main-source.yml index a40203388c..d362a49a1d 100644 --- a/.github/workflows/update-main-source.yml +++ b/.github/workflows/update-main-source.yml @@ -36,6 +36,6 @@ jobs: # push changes git push --set-upstream origin "$BRANCH" - TITLE="Auto-update charts on main-source" + TITLE="[AUTOMATED] Auto-update charts on main-source" BODY="This PR was created by the \"$GITHUB_WORKFLOW\" workflow. It auto-updates the helm charts on the main-source branch." gh pr create --repo "$GITHUB_REPOSITORY" --base main-source --head "$BRANCH" --title "$TITLE" --body "$BODY" From b224e06d549dcbdee715a367a573f2b804ae453e Mon Sep 17 00:00:00 2001 From: Adam Pickering Date: Mon, 11 Mar 2024 15:30:16 -0600 Subject: [PATCH 6/6] Add --no-run-if-empty option to xargs command Without this option, xargs will run the `gh pr close` command with no arguments when `gh pr list` outputs no PRs. Adding this option prevents the error that can result. --- .github/workflows/update-main-source.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-main-source.yml b/.github/workflows/update-main-source.yml index d362a49a1d..92df6ab978 100644 --- a/.github/workflows/update-main-source.yml +++ b/.github/workflows/update-main-source.yml @@ -32,7 +32,7 @@ jobs: # close all existing PRs from branches starting with "auto-update" gh pr --repo "$GITHUB_REPOSITORY" list --search 'head:auto-update' --json 'headRefName' --jq '.[] | join("\n")' | \ - xargs -n 1 gh pr --repo "$GITHUB_REPOSITORY" close + xargs --no-run-if-empty -n 1 gh pr --repo "$GITHUB_REPOSITORY" close # push changes git push --set-upstream origin "$BRANCH"