continuous-delivery #338
This file contains 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: continuous-delivery | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 1 * * *' | |
# set up environment variables to be used across all the jobs | |
env: | |
GOLANG_VERSION: "1.20.x" | |
KIND_VERSION: "v0.20.0" | |
REGISTRY: "ghcr.io/cloudnative-pg/postgresql-trunk" | |
POSTGRES_VERSION: "16-devel" | |
defaults: | |
run: | |
# default failure handling for shell scripts in 'run' steps | |
shell: 'bash -Eeuo pipefail -x {0}' | |
jobs: | |
build-pg: | |
name: Build the Trunk of PostgreSQL | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: read | |
packages: write | |
outputs: | |
POSTGRES_IMG: ${{ steps.set-env.outputs.POSTGRES_IMG }} | |
E2E_PRE_ROLLING_UPDATE_IMG: ${{ steps.set-env.outputs.E2E_PRE_ROLLING_UPDATE_IMG }} | |
steps: | |
- name: Set Global Env Vars | |
id: set-env | |
run: | | |
postgres_img="${{ env.REGISTRY }}:${{ env.POSTGRES_VERSION }}" | |
# The version of operator to upgrade FROM, in the rolling upgrade E2E test | |
e2e_pre_rolling_update_image="${postgres_img}-1" | |
echo "POSTGRES_IMG=${postgres_img}" >> $GITHUB_OUTPUT | |
echo "E2E_PRE_ROLLING_UPDATE_IMG=${e2e_pre_rolling_update_image}" >> $GITHUB_OUTPUT | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Log in to the GitHub Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and load | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
load: false | |
tags: | | |
${{ steps.set-env.outputs.POSTGRES_IMG }} | |
${{ steps.set-env.outputs.E2E_PRE_ROLLING_UPDATE_IMG }} | |
e2e-local: | |
name: Run E2E on local executors | |
needs: | |
- build-pg | |
runs-on: ubuntu-22.04 | |
env: | |
TEST_DEPTH: 4 | |
K8S_VERSION: "v1.27.3" | |
ID: "local" | |
POSTGRES_KIND: "PostgreSQL" | |
DOCKER_SERVER: ghcr.io | |
DOCKER_USERNAME: ${{ github.actor }} | |
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
TEST_UPGRADE_TO_V1: false | |
BRANCH_NAME: main | |
POSTGRES_IMG: ${{ needs.build-pg.outputs.POSTGRES_IMG }} | |
E2E_PRE_ROLLING_UPDATE_IMG: ${{ needs.build-pg.outputs.E2E_PRE_ROLLING_UPDATE_IMG }} | |
DEBUG: "true" | |
BUILD_IMAGE: "true" | |
E2E_DEFAULT_STORAGE_CLASS: standard | |
E2E_CSI_STORAGE_CLASS: csi-hostpath-sc | |
E2E_DEFAULT_VOLUMESNAPSHOT_CLASS: csi-hostpath-snapclass | |
LOG_DIR: ${{ github.workspace }}/kind-logs/ | |
DOCKER_REGISTRY_MIRROR: https://mirror.gcr.io | |
TEST_CLOUD_VENDOR: "local" | |
steps: | |
- name: Cleanup Disk | |
uses: jlumbroso/free-disk-space@main | |
with: | |
android: true | |
dotnet: true | |
haskell: true | |
large-packages: false | |
swap-storage: true | |
- name: Cleanup docker cache | |
run: | | |
echo "-------------Disk info before cleanup----------------" | |
df -h | |
echo "-----------------------------------------------------" | |
docker system prune -a -f | |
echo "-------------Disk info after cleanup----------------" | |
df -h | |
echo "-----------------------------------------------------" | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: cloudnative-pg/cloudnative-pg | |
ref: main | |
fetch-depth: 0 | |
- name: Install Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GOLANG_VERSION }} | |
- name: Set GoReleaser environment | |
run: | | |
echo GOPATH=$(go env GOPATH) >> $GITHUB_ENV | |
echo PWD=$(pwd) >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Prepare the environment | |
uses: nick-fields/retry@v2 | |
with: | |
timeout_seconds: 120 | |
max_attempts: 3 | |
on_retry_command: | | |
# Clear-ups before retries | |
rm -rf /usr/local/bin/kind /usr/local/bin/kubectl | |
command: | | |
sudo apt-get update | |
sudo apt-get install -y gettext-base | |
sudo hack/setup-cluster.sh prepare /usr/local/bin | |
- name: Run Kind End-to-End tests | |
run: make e2e-test-kind | |
# Summarize the failed E2E test cases if there are any | |
- name: Report failed E2E tests | |
if: failure() | |
run: | | |
set +x | |
chmod +x .github/report-failed-test.sh | |
./.github/report-failed-test.sh | |
# Create an individual artifact for each E2E test, which will be used to | |
# generate E2E test summary in the follow-up job 'summarize-e2e-tests' | |
- name: Create individual artifact for each E2E test | |
if: (always() && !cancelled()) | |
run: | | |
set +x | |
echo '{"runner": "local", "postgres": "${{env.POSTGRES_VERSION}}", "postgres_kind": "${{env.POSTGRES_KIND}}", "kubernetes": "${{env.K8S_VERSION}}", "runid": ${{ github.run_id }}, "id": "local-PostgreSQL"-${{ env.POSTGRES_VERSION }}", "repo": "${{github.repository}}", "branch": "${GITHUB_REF#refs/heads/}", "refname": "${{github.ref_name}}" }' | |
python .github/generate-test-artifacts.py \ | |
-o testartifacts-${{ env.ID }} \ | |
-f tests/e2e/out/report.json \ | |
-m '{"runner": "local", "postgres": "${{env.POSTGRES_VERSION}}", "postgres_kind": "${{env.POSTGRES_KIND}}", "kubernetes": "${{env.K8S_VERSION}}", "runid": ${{ github.run_id }}, "id": "${{ env.ID }}", "repo": "${{github.repository}}", "branch": "${GITHUB_REF#refs/heads/}", "refname": "${{github.ref_name}}" }' | |
if [ -f tests/e2e/out/upgrade_report.json ]; then | |
python .github/generate-test-artifacts.py \ | |
-o testartifacts-${{ env.ID }} \ | |
-f tests/e2e/out/upgrade_report.json \ | |
-m '{"runner": "local", "postgres": "${{env.POSTGRES_VERSION}}", "postgres_kind": "${{env.POSTGRES_KIND}}", "kubernetes": "${{env.K8S_VERSION}}", "runid": ${{ github.run_id }}, "id": "${{ env.ID }}", "repo": "${{github.repository}}", "branch": "${GITHUB_REF#refs/heads/}", "refname": "${{github.ref_name}}" }' | |
fi | |
- name: Archive test artifacts | |
if: (always() && !cancelled()) | |
uses: actions/upload-artifact@v3 | |
with: | |
name: testartifacts-local | |
path: testartifacts-${{ env.ID }}/ | |
retention-days: 7 | |
- name: Cleanup test artifacts | |
if: always() | |
run: | |
rm -rf testartifacts-${{ env.ID }}/ | |
# Delete report.json after the analysis. File should always exist. | |
# Delete upgrade_report.json. It may not exist depending on test level. | |
- name: Cleanup ginkgo JSON report | |
if: always() | |
run: | | |
if [ -f tests/e2e/out/upgrade_report.json ]; then | |
rm tests/e2e/out/upgrade_report.json | |
fi | |
rm tests/e2e/out/report.json | |
# Archive logs for failed test cases if there are any | |
- name: Archive Kind logs | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: kind-logs-${{ env.ID }} | |
path: kind-logs/ | |
retention-days: 7 | |
- name: Archive e2e failure contexts | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-failure-contexts-${{ env.ID }} | |
path: | | |
tests/*/out/ | |
retention-days: 7 | |
if-no-files-found: ignore | |
# Summarize E2E test results, display in the GitHub 'summary' view | |
summarize-e2e-tests: | |
name: E2E test suite | |
needs: | |
- e2e-local | |
if: | | |
always() && !cancelled() && | |
( | |
needs.e2e-local.result == 'success' || | |
needs.e2e-local.result == 'failure' | |
) | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Create a directory for the artifacts | |
run: mkdir test-artifacts | |
- name: Download all artifacts to the directory | |
uses: actions/download-artifact@v3 | |
with: | |
path: test-artifacts | |
- name: Flatten all artifacts onto directory | |
# The download-artifact action, since we did not give it a name, | |
# downloads all artifacts and creates a new folder for each. | |
# In this step we bring all the JSONs to a single folder | |
run: | | |
mkdir test-artifacts/data | |
mv test-artifacts/*/*.json test-artifacts/data | |
- name: Display the structure of the artifact folder | |
run: ls -R test-artifacts/data | |
- name: Compute the E2E test summary | |
uses: cloudnative-pg/[email protected] | |
with: | |
artifact_directory: test-artifacts/data | |
- name: Delete the downloaded files | |
run: rm -rf test-artifacts |