Files
peaklabs-dev aefd2cff89 feat(release): copy the image labels to the release index
- ghcr.io reads the description and the license of an image of several platforms from the annotations of its index, not from the labels of each image
2026-11-02 00:06:48 +01:00

123 lines
4.1 KiB
YAML

name: Pull request
on:
pull_request:
permissions: {}
cache-mode: none
concurrency:
group: pull-request-${{ github.event.pull_request.number }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
detect:
name: Detect release push
permissions:
contents: read
runs-on: ubuntu-26.04 # https://github.com/actions/runner-images
timeout-minutes: 10
outputs:
release: ${{ steps.detect.outputs.release }}
steps:
- name: Check whether the push releases
id: detect
env:
GH_TOKEN: ${{ github.token }}
ACTION: ${{ github.event.action }}
HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
HEAD_BRANCH: ${{ github.head_ref }}
BEFORE: ${{ github.event.before }}
AFTER: ${{ github.event.after }}
run: |
release=false
if [ "$ACTION" = synchronize ] && [ "$HEAD_REPOSITORY" = "$GITHUB_REPOSITORY" ] \
&& [[ "$HEAD_BRANCH" =~ ^(main|next|v[0-9]+(\.[0-9]+)?\.x|release/v[0-9]+\.[0-9]+)$ ]]; then
files="$(gh api "repos/$GITHUB_REPOSITORY/compare/$BEFORE...$AFTER" --jq '.files[].filename')"
! grep -qxE 'release\.json' <<< "$files" || release=true
fi
echo "release=$release" | tee -a "$GITHUB_OUTPUT"
build:
name: Build
needs: detect
if: ${{ needs.detect.outputs.release == 'false' }}
permissions:
contents: read
uses: $/.github/workflows/build.yaml
publish:
name: Publish image
needs: build
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
permissions:
packages: write # push the image of the pull request to ghcr.io
runs-on: ubuntu-26.04 # https://github.com/actions/runner-images
timeout-minutes: 30
steps:
- name: Download the built images
uses: actions/download-artifact@v8.0.2
with:
pattern: image-*
path: ${{ runner.temp }}/images
- name: Log in to ghcr.io
uses: docker/login-action@v4.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push the image of the pull request
env:
TAG: pr-${{ github.event.pull_request.number }}
run: |
sources=()
for index in "$RUNNER_TEMP"/images/*/index.json; do
sources+=("oci-layout://${index%/index.json}@$(jq -r '.manifests[0].digest' "$index")")
done
labels="$(docker buildx imagetools inspect "${sources[0]}" --format '{{ json .Image.Config.Labels }}' \
| jq -r 'to_entries[] | "--annotation=index:\(.key)=\(.value)"')"
mapfile -t annotations <<< "$labels"
docker buildx imagetools create "${annotations[@]}" --tag "ghcr.io/coollabsio/coolify:$TAG" "${sources[@]}"
size:
name: Compare size with latest
needs: build
permissions:
contents: read
pull-requests: write # comment the size report on the pull request
runs-on: ubuntu-26.04 # https://github.com/actions/runner-images
timeout-minutes: 30
steps:
- name: Check out the repository
uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- name: Download the built images
uses: actions/download-artifact@v8.0.2
with:
pattern: image-*
path: ${{ runner.temp }}/images
- name: Compare the size with the latest release
env:
IMAGE_NAME: pr-${{ github.event.pull_request.number }}
OUTPUT_FILE: ${{ runner.temp }}/size.md
run: |
scripts/size.sh "$RUNNER_TEMP/images" coollabsio/coolify:latest
cat "$OUTPUT_FILE" >> "$GITHUB_STEP_SUMMARY"
- name: Comment the size on the pull request
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
env:
GH_TOKEN: ${{ github.token }}
PULL_REQUEST: ${{ github.event.pull_request.number }}
run: gh pr comment "$PULL_REQUEST" --body-file "$RUNNER_TEMP/size.md" --edit-last --create-if-none