Kratix #33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Kratix | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| sha: | |
| description: 'Commit sha of Kratix' | |
| required: true | |
| message: | |
| description: 'Commit message' | |
| required: false | |
| jobs: | |
| set-pending-status: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Generate GitHub App token | |
| id: generate-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.AUTOMATION_APP_ID }} | |
| private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }} | |
| repositories: kratix | |
| - name: Set pending status | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ steps.generate-token.outputs.token }} | |
| script: | | |
| const statusContext = 'ci-tests'; | |
| const runId = process.env.GITHUB_RUN_ID || 'unknown'; | |
| const sha = '${{ github.event.inputs.sha }}' | |
| try { | |
| await github.rest.repos.createCommitStatus({ | |
| owner: 'syntasso', | |
| repo: 'kratix', | |
| sha: sha, | |
| state: 'pending', | |
| target_url: `https://github.com/syntasso/ci/actions/runs/${runId}`, | |
| description: 'CI tests in progress', | |
| context: statusContext | |
| }); | |
| core.info('Successfully set pending status'); | |
| } catch (error) { | |
| core.setFailed(`Failed to set pending status: ${error.message}`); | |
| } | |
| unit-tests-and-lint: | |
| runs-on: ubuntu-latest | |
| needs: [set-pending-status] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: syntasso/kratix | |
| ref: ${{ github.event.inputs.sha }} | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.22 | |
| check-latest: true | |
| - name: Unit Tests | |
| run: | | |
| make test | |
| - name: Lint | |
| run: | | |
| curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.63.4 | |
| ./bin/golangci-lint run --config=.golangci-required.yml | |
| system-test: | |
| runs-on: ubuntu-latest | |
| needs: [unit-tests-and-lint] | |
| steps: | |
| - name: Check out kratix | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: syntasso/kratix | |
| ref: ${{ github.event.inputs.sha }} | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.22 | |
| check-latest: true | |
| - name: Install Kind | |
| uses: helm/kind-action@v1 | |
| with: | |
| install_only: true | |
| - name: Setup Flux CLI | |
| uses: fluxcd/flux2/action@main | |
| with: | |
| version: '2.4.0' | |
| - name: System Tests | |
| run: | | |
| DOCKER_BUILDKIT=1 ACK_GINKGO_RC=true make system-test core-test | |
| integration-test: | |
| runs-on: ubuntu-latest | |
| needs: [unit-tests-and-lint] | |
| steps: | |
| - name: Check out kratix | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: syntasso/kratix | |
| ref: ${{ github.event.inputs.sha }} | |
| - name: Checkout out kratix helm charts | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: syntasso/helm-charts | |
| path: charts | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.22 | |
| check-latest: true | |
| - name: Install Kind | |
| uses: helm/kind-action@v1 | |
| with: | |
| install_only: true | |
| - name: Install Helm | |
| uses: azure/setup-helm@v3 | |
| - name: e2e-demo-test-helm-bucket | |
| run: | | |
| STATE_STORE="bucket" ./scripts/helm-e2e-test.sh | |
| - name: e2e-demo-test-helm-git | |
| run: | | |
| STATE_STORE="git" ./scripts/helm-e2e-test.sh | |
| tag-new-version: | |
| needs: [system-test, integration-test] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out kratix | |
| id: checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ssh-key: ${{ secrets.ACTION_PUSH }} | |
| repository: syntasso/kratix | |
| ref: ${{ github.event.inputs.sha }} | |
| - name: Tag new version | |
| env: | |
| LAST_SHA: ${{ github.event.inputs.sha }} | |
| run: | | |
| latest_tag="latest" | |
| current_commit=${LAST_SHA:-$(git rev-parse HEAD)} | |
| commit_list=$(git rev-list "$latest_tag".."$current_commit") | |
| git config user.name "syntassodev" | |
| git config user.email "[email protected]" | |
| echo "checking if there are new commits from main compared to the latest tag" | |
| if [ -n "$commit_list" ]; then | |
| echo "Current commit is ahead of the previous tag; pushing a new tag" | |
| git tag -a $latest_tag -m "${latest_tag}" --force | |
| git push origin $latest_tag --force | |
| else | |
| echo "Current commit is not ahead of the previous tag; not pushing a new tag" | |
| fi | |
| build-and-push-kratix-platform: | |
| runs-on: ubuntu-latest | |
| needs: [tag-new-version] | |
| steps: | |
| - name: Check out kratix | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: syntasso/kratix | |
| ref: ${{ github.event.inputs.sha }} | |
| - name: Docker login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Kratix Platform | |
| run: | | |
| make docker-build-and-push | |
| build-and-push-pipeline-adapter: | |
| runs-on: ubuntu-latest | |
| needs: [tag-new-version] | |
| steps: | |
| - name: Check out kratix | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: syntasso/kratix | |
| ref: ${{ github.event.inputs.sha }} | |
| - name: Docker login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Pipeline | |
| run: | | |
| make build-and-push-work-creator | |
| publish-release: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-and-push-kratix-platform | |
| - build-and-push-pipeline-adapter | |
| steps: | |
| - name: Check out kratix | |
| uses: actions/checkout@v4 | |
| id: checkout | |
| with: | |
| repository: syntasso/kratix | |
| ref: ${{ github.event.inputs.sha }} | |
| - name: Checkout out kratix helm charts | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: syntasso/helm-charts | |
| path: charts | |
| ssh-key: ${{ secrets.HELM_REPO_SSH_KEY }} | |
| - name: Create Kratix Distribution and Helm Template | |
| run: | | |
| ./scripts/make-distribution | |
| ./charts/scripts/generate-templates-and-crds ./distribution/kratix.yaml | |
| env: | |
| VERSION: ${{ steps.checkout.outputs.commit }} | |
| - name: Create Github Release | |
| run: | | |
| gh config set prompt disabled | |
| gh release delete latest || true | |
| gh release create latest --title latest ./distribution/**/*.yaml ./distribution/*.yaml | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_RELEASE_CREATOR_TOKEN }} | |
| - name: push-to-helm-charts | |
| run: | | |
| cd charts | |
| git config user.name “syntassodev” | |
| git config user.email “[email protected]” | |
| git add kratix/ | |
| git diff --cached --quiet && exit 0 || true | |
| git commit -m"update kratix package" | |
| git push origin main | |
| final-status-check: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - set-pending-status | |
| - unit-tests-and-lint | |
| - system-test | |
| - integration-test | |
| - tag-new-version | |
| - build-and-push-kratix-platform | |
| - build-and-push-pipeline-adapter | |
| - publish-release | |
| if: always() | |
| steps: | |
| - name: Generate GitHub App token | |
| id: generate-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.AUTOMATION_APP_ID }} | |
| private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }} | |
| repositories: kratix | |
| - name: Update Kratix commit status | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ steps.generate-token.outputs.token }} | |
| script: | | |
| const statusContext = 'ci-tests'; | |
| const runId = process.env.GITHUB_RUN_ID || 'unknown'; | |
| const sha = '${{ github.event.inputs.sha }}' | |
| // Collect job results from workflow context | |
| const jobResults = [ | |
| '${{ needs.unit-tests-and-lint.result }}', | |
| '${{ needs.system-test.result }}', | |
| '${{ needs.integration-test.result }}', | |
| '${{ needs.tag-new-version.result }}', | |
| '${{ needs.build-and-push-kratix-platform.result }}', | |
| '${{ needs.build-and-push-pipeline-adapter.result }}', | |
| '${{ needs.publish-release.result }}' | |
| ]; | |
| const hasFailed = jobResults.some(result => | |
| result === 'failure' || | |
| result === 'timed_out' || | |
| result === 'cancelled' | |
| ); | |
| const state = hasFailed ? 'failure' : 'success'; | |
| const description = hasFailed ? 'CI workflow failed' : 'CI workflow passed'; | |
| try { | |
| await github.rest.repos.createCommitStatus({ | |
| owner: 'syntasso', | |
| repo: 'kratix', | |
| sha: sha, | |
| state: state, | |
| target_url: `https://github.com/syntasso/ci/actions/runs/${runId}`, | |
| description: description, | |
| context: statusContext | |
| }); | |
| core.info(`Successfully set final status to ${state}`); | |
| } catch (error) { | |
| core.setFailed(`Failed to set final status: ${error.message}`); | |
| } |