CI working with job summaries

All images should be generating correctly with parallelism and Docker manifests, and should output the end of the CI testing errors in a job summary box when the test fails.

When the test succeeds you get a big  then at the end of the Docker publish it should include the `docker pull` commands for both Docker Hub and GHCR registries to make those pesky Docker users lives easier!
This commit is contained in:
Tom Foster 2024-04-26 01:11:12 +01:00 committed by June
parent aa299111a4
commit 536efe2cd7

View file

@ -26,7 +26,7 @@ permissions:
jobs: jobs:
tests: tests:
name: Prepare and test name: Test
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Sync repository - name: Sync repository
@ -59,19 +59,27 @@ jobs:
extra-trusted-public-keys = ${{ env.ATTIC_PUBLIC_KEY }} extra-trusted-public-keys = ${{ env.ATTIC_PUBLIC_KEY }}
EOF EOF
- name: Install and activate `direnv` - name: Prepare build environment
run: | run: |
echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > "$HOME/.direnvrc" echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > "$HOME/.direnvrc"
nix-env -f "<nixpkgs>" -iA direnv -iA nix-direnv nix-env -f "<nixpkgs>" -iA direnv -iA nix-direnv
direnv allow direnv allow
- name: Update `/nix/store`
run: |
nix develop --command true nix develop --command true
- name: Run CI tests - name: Run CI tests
run: | run: |
direnv exec . engage direnv exec . engage > >(tee -a test_output.log)
- name: Update Job Summary
if: success() || failure()
run: |
if [ ${{ job.status }} == 'success' ]; then
echo '# ✅' >> $GITHUB_STEP_SUMMARY
else
echo '```' >> $GITHUB_STEP_SUMMARY
tail -n 20 test_output.log | sed 's/\x1b\[[0-9;]*m//g' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
fi
build: build:
name: Build name: Build
@ -116,14 +124,11 @@ jobs:
extra-trusted-public-keys = ${{ env.ATTIC_PUBLIC_KEY }} extra-trusted-public-keys = ${{ env.ATTIC_PUBLIC_KEY }}
EOF EOF
- name: Install and activate `direnv` - name: Prepare build environment
run: | run: |
echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > "$HOME/.direnvrc" echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > "$HOME/.direnvrc"
nix-env -f "<nixpkgs>" -iA direnv -iA nix-direnv nix-env -f "<nixpkgs>" -iA direnv -iA nix-direnv
direnv allow direnv allow
- name: Update `/nix/store`
run: |
nix develop --command true nix develop --command true
- name: Build static ${{ matrix.target }} - name: Build static ${{ matrix.target }}
@ -162,10 +167,19 @@ jobs:
compression-level: 0 compression-level: 0
docker: docker:
name: Publish Docker manifests name: Docker publish
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build needs: build
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name != 'pull_request' if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name != 'pull_request'
env:
DOCKER_ARM64: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8
DOCKER_AMD64: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64
DOCKER_TAG: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}
DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (github.ref == 'refs/heads/main' && 'latest') || github.ref_name }}
GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8
GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64
GHCR_TAG: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}
GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (github.ref == 'refs/heads/main' && 'latest') || github.ref_name }}
steps: steps:
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
@ -184,38 +198,42 @@ jobs:
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
- name: Create and push manifests to GitHub and Docker Hub - name: Move OCI images into position
env:
BRANCH_TAG: ${{ github.ref_name }}
run: | run: |
mv oci-image-*/oci-image-*.tar.gz . mv oci-image-x86_64-*-jemalloc/*.tar.gz oci-image-amd64.tar.gz
docker load -i oci-image-aarch64-unknown-linux-musl-jemalloc.tar.gz mv oci-image-aarch64-*-jemalloc/*.tar.gz oci-image-arm64v8.tar.gz
docker tag $(docker images -q conduit:main) conduwuit:${{ github.sha }}-aarch64-jemalloc
docker load -i oci-image-x86_64-unknown-linux-musl-jemalloc.tar.gz
docker tag $(docker images -q conduit:main) conduwuit:${{ github.sha }}-x86_64-jemalloc
if [ "$BRANCH_TAG" == "main" ]; then - name: Load and push amd64 image
BRANCH_TAG="latest" run: |
fi docker load -i oci-image-amd64.tar.gz
docker tag $(docker images -q conduit:main) ${{ env.DOCKER_AMD64 }}
docker tag $(docker images -q conduit:main) ${{ env.GHCR_AMD64 }}
docker push ${{ env.DOCKER_AMD64 }}
docker push ${{ env.GHCR_AMD64 }}
# Creating and pushing for GitHub Container Registry - name: Load and push arm64 image
docker manifest create ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} \ run: |
--amend conduwuit:${{ github.sha }}-x86_64-jemalloc \ docker load -i oci-image-arm64v8.tar.gz
--amend conduwuit:${{ github.sha }}-aarch64-jemalloc docker tag $(docker images -q conduit:main) ${{ env.DOCKER_ARM64 }}
docker manifest push ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} docker tag $(docker images -q conduit:main) ${{ env.GHCR_ARM64 }}
docker push ${{ env.DOCKER_ARM64 }}
docker push ${{ env.GHCR_ARM64 }}
docker manifest create ghcr.io/${{ github.repository }}:$BRANCH_TAG \ - name: Create Docker combined manifests
--amend conduwuit:${{ github.sha }}-x86_64-jemalloc \ run: |
--amend conduwuit:${{ github.sha }}-aarch64-jemalloc docker manifest create ${{ env.DOCKER_TAG }} --amend ${{ env.DOCKER_ARM64 }} --amend ${{ env.DOCKER_AMD64 }}
docker manifest push ghcr.io/${{ github.repository }}:$BRANCH_TAG docker manifest create ${{ env.DOCKER_BRANCH }} --amend ${{ env.DOCKER_ARM64 }} --amend ${{ env.DOCKER_AMD64 }}
docker manifest create ${{ env.GHCR_TAG }} --amend ${{ env.GHCR_ARM64 }} --amend ${{ env.GHCR_AMD64 }}
docker manifest create ${{ env.GHCR_BRANCH }} --amend ${{ env.GHCR_ARM64 }} --amend ${{ env.GHCR_AMD64 }}
# Creating and pushing for Docker Hub - name: Push manifests to Docker registries
docker manifest create docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} \ run: |
--amend conduwuit:${{ github.sha }}-x86_64-jemalloc \ docker manifest push ${{ env.DOCKER_TAG }}
--amend conduwuit:${{ github.sha }}-aarch64-jemalloc docker manifest push ${{ env.DOCKER_BRANCH }}
docker manifest push docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} docker manifest push ${{ env.GHCR_TAG }}
docker manifest push ${{ env.GHCR_BRANCH }}
docker manifest create docker.io/${{ github.repository }}:$BRANCH_TAG \ - name: Add Image Links to Job Summary
--amend conduwuit:${{ github.sha }}-x86_64-jemalloc \ run: |
--amend conduwuit:${{ github.sha }}-aarch64-jemalloc echo "- \`docker pull ${{ env.DOCKER_TAG }}\`" >> $GITHUB_STEP_SUMMARY
docker manifest push docker.io/${{ github.repository }}:$BRANCH_TAG echo "- \`docker pull ${{ env.GHCR_TAG }}\`" >> $GITHUB_STEP_SUMMARY