diff --git a/.github/workflows/build-and-upload.yaml b/.github/workflows/build-and-publish-standalone.yaml similarity index 99% rename from .github/workflows/build-and-upload.yaml rename to .github/workflows/build-and-publish-standalone.yaml index c66afae2..eda93b6f 100644 --- a/.github/workflows/build-and-upload.yaml +++ b/.github/workflows/build-and-publish-standalone.yaml @@ -1,4 +1,4 @@ -name: Build Harvester Dashboard and Upload +name: Build Harvester Dashboard and Publish on: workflow_call: diff --git a/.github/workflows/build-extension-on-merge.yml b/.github/workflows/build-extension-on-merge.yml new file mode 100644 index 00000000..da94cfeb --- /dev/null +++ b/.github/workflows/build-extension-on-merge.yml @@ -0,0 +1,136 @@ +name: Build and Release Extension Charts on PR Merge + +on: + push: + branches: + - 'release-harvester-v*' + +jobs: + setup-target-branch: + runs-on: ubuntu-latest + outputs: + target_branch: ${{ steps.get-version.outputs.target_branch }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Determine target branch + id: get-version + run: | + if [[ "${{ github.ref_name }}" =~ ^release-harvester-v([0-9]+\.[0-9]+)$ ]]; then + TARGET_BRANCH="v${BASH_REMATCH[1]}-head" + echo "target_branch=${TARGET_BRANCH}" >> $GITHUB_ENV + echo "target_branch=${TARGET_BRANCH}" >> $GITHUB_OUTPUT + else + echo "Error: invalid branch format." && exit 1 + fi + + - name: Ensure target branch exists + run: | + git fetch --all + if ! git ls-remote --exit-code --heads origin "${{ env.target_branch }}"; then + git checkout gh-pages + git checkout -b "${{ env.target_branch }}" + git push origin "${{ env.target_branch }}" + fi + + extract-version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.version }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Extract version from package.json + id: get_version + run: | + VERSION=$(jq -r '.version' pkg/harvester/package.json) + echo "VERSION=${VERSION}" >> $GITHUB_ENV + echo "version=${VERSION}" >> $GITHUB_OUTPUT + + build-extension-charts: + needs: + - setup-target-branch + - extract-version + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup environment + run: | + corepack enable + yarn install --frozen-lockfile + + - name: Setup Helm + uses: azure/setup-helm@v3 + with: + version: v3.8.0 + + - name: Build Helm charts + run: | + yarn publish-pkgs -s ${{ github.repository }} -b ${{ needs.setup-target-branch.outputs.target_branch }} -t harvester-${{ needs.extract-version.outputs.version }} + + - name: Upload charts artifact + uses: actions/upload-artifact@v4 + with: + name: charts + path: tmp + + release: + needs: + - setup-target-branch + - extract-version + - build-extension-charts + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout release branch + uses: actions/checkout@v4 + with: + ref: '${{ github.ref_name }}' + + - name: Get last commit hash + id: last_commit + run: | + LAST_COMMIT=$(git rev-parse HEAD) + echo "LAST_COMMIT=${LAST_COMMIT}" >> $GITHUB_ENV + + - name: Checkout target branch + uses: actions/checkout@v4 + with: + ref: '${{ needs.setup-target-branch.outputs.target_branch }}' + + - name: Remove old artifacts + run: | + rm -rf extensions/harvester/${{ needs.extract-version.outputs.version }} + rm -rf charts/harvester/${{ needs.extract-version.outputs.version }} + rm -f assets/harvester/harvester-${{ needs.extract-version.outputs.version }}.tgz + + - name: Configure Git + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: charts + + - name: Commit and push artifacts + run: | + git add ./{assets,charts,extensions,index.yaml} + git commit -m "CI Build Artifacts (commit: ${{ env.LAST_COMMIT }}, version: ${{ needs.extract-version.outputs.version }})" + git push origin ${{ needs.setup-target-branch.outputs.target_branch }} + + - name: Run Helm chart releaser + uses: helm/chart-releaser-action@v1.4.1 + with: + charts_dir: ./charts + env: + CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + CR_SKIP_EXISTING: true diff --git a/.github/workflows/build-extension-charts.yml b/.github/workflows/build-extension-on-release.yml similarity index 85% rename from .github/workflows/build-extension-charts.yml rename to .github/workflows/build-extension-on-release.yml index 88c840d3..d2b223e4 100644 --- a/.github/workflows/build-extension-charts.yml +++ b/.github/workflows/build-extension-on-release.yml @@ -1,4 +1,4 @@ -name: Build and Release Extension Charts +name: Build and Release Extension Charts on Release on: workflow_dispatch: @@ -31,4 +31,4 @@ jobs: pages: write with: target_branch: gh-pages - tagged_release: ${{ github.ref_name }} + tagged_release: ${{ github.ref_name }} \ No newline at end of file diff --git a/.github/workflows/build-and-upload-branch.yaml b/.github/workflows/build-standalone-on-merge.yaml similarity index 74% rename from .github/workflows/build-and-upload-branch.yaml rename to .github/workflows/build-standalone-on-merge.yaml index ad786c66..37de28e8 100644 --- a/.github/workflows/build-and-upload-branch.yaml +++ b/.github/workflows/build-standalone-on-merge.yaml @@ -1,4 +1,4 @@ -name: Build Dashboard (Branch) +name: Build Standalone on PR Merge on: push: @@ -11,16 +11,16 @@ on: - main - 'release-harvester-v*' - '*-dev' - types: + types: - merged jobs: build-validation: name: Build Test - uses: ./.github/workflows/test.yaml + uses: ./.github/workflows/run-lint.yaml build: name: Build and Upload Package - uses: ./.github/workflows/build-and-upload.yaml + uses: ./.github/workflows/build-and-publish-standalone.yaml needs: - build-validation permissions: diff --git a/.github/workflows/build-and-upload-release.yaml b/.github/workflows/build-standalone-on-release.yaml similarity index 67% rename from .github/workflows/build-and-upload-release.yaml rename to .github/workflows/build-standalone-on-release.yaml index b0829606..d0eacdef 100644 --- a/.github/workflows/build-and-upload-release.yaml +++ b/.github/workflows/build-standalone-on-release.yaml @@ -1,4 +1,4 @@ -name: Build Dashboard (Release) +name: Build Standalone on Release on: push: tags: @@ -7,10 +7,10 @@ on: jobs: build-validation: name: Build Test - uses: ./.github/workflows/test.yaml + uses: ./.github/workflows/run-lint.yaml build: name: Build and Upload Package - uses: ./.github/workflows/build-and-upload.yaml + uses: ./.github/workflows/build-and-publish-standalone.yaml needs: - build-validation permissions: diff --git a/.github/workflows/test.yaml b/.github/workflows/run-lint.yaml similarity index 100% rename from .github/workflows/test.yaml rename to .github/workflows/run-lint.yaml