mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2025-12-13 13:11:43 +00:00
ci: add ci pipeline
Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
This commit is contained in:
parent
2255bd4f69
commit
30e49a6f2c
136
.github/workflows/build-extension-charts-on-pr-merge.yml
vendored
Normal file
136
.github/workflows/build-extension-charts-on-pr-merge.yml
vendored
Normal file
@ -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
|
||||
64
.github/workflows/build-extension-charts-on-release.yml
vendored
Normal file
64
.github/workflows/build-extension-charts-on-release.yml
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
name: Build and Release Extension Charts
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [released]
|
||||
pull_request:
|
||||
branches:
|
||||
- "release-harvester-v*"
|
||||
types:
|
||||
- merged
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: ./
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Run tests
|
||||
uses: ./.github/actions/lint
|
||||
|
||||
build-extension-charts:
|
||||
needs:
|
||||
- lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Determine target branch
|
||||
id: set_target
|
||||
run: |
|
||||
if [[ "${{ github.event_name }}" == "release" ]]; then
|
||||
echo "TARGET_BRANCH=gh-pages" >> $GITHUB_ENV
|
||||
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
|
||||
VERSION=$(echo "${{ github.ref }}" | sed -n 's/refs\/heads\/release-harvester-v\(.*\)/v\1-head/p')
|
||||
if [[ -n "$VERSION" ]]; then
|
||||
echo "TARGET_BRANCH=$VERSION" >> $GITHUB_ENV
|
||||
else
|
||||
echo "Error: Could not determine target branch."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Skipping build. No matching condition."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
- name: Build and push extension charts
|
||||
if: env.TARGET_BRANCH != ''
|
||||
uses: rancher/dashboard/.github/workflows/build-extension-charts.yml@master
|
||||
permissions:
|
||||
actions: write
|
||||
contents: write
|
||||
deployments: write
|
||||
pages: write
|
||||
with:
|
||||
target_branch: ${{ env.TARGET_BRANCH }}
|
||||
tagged_release: ${{ github.ref_name }}
|
||||
53
.github/workflows/build-extension-charts.yml
vendored
53
.github/workflows/build-extension-charts.yml
vendored
@ -1,53 +0,0 @@
|
||||
name: Build and Release Extension Charts
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [released]
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: ./
|
||||
|
||||
jobs:
|
||||
setup-release-tag:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
release_tag: ${{ steps.determine_tag.outputs.release_tag }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Determine release tag
|
||||
id: determine_tag
|
||||
run: |
|
||||
if [[ "${{ github.ref_name }}" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
|
||||
RELEASE_TAG="harvester-${BASH_REMATCH[1]}"
|
||||
echo "${RELEASE_TAG}"
|
||||
echo "release_tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Error: invalid tag format." && exit 1
|
||||
fi
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Run tests
|
||||
uses: ./.github/actions/lint
|
||||
build-extension-charts:
|
||||
needs:
|
||||
- setup-release-tag
|
||||
- lint
|
||||
uses: rancher/dashboard/.github/workflows/build-extension-charts.yml@master
|
||||
permissions:
|
||||
actions: write
|
||||
contents: write
|
||||
deployments: write
|
||||
pages: write
|
||||
with:
|
||||
target_branch: gh-pages
|
||||
tagged_release: '${{ needs.setup-release-tag.outputs.release_tag }}'
|
||||
Loading…
x
Reference in New Issue
Block a user