Repository navigation
127 lines (111 loc) · 4.12 KB
/
Copy pathpull-request.yaml
File metadata and controls
127 lines (111 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Pull request
on:
pull_request:
permissions: {}
cache-mode: none
concurrency:
group: pull-request-${{ github.event.pull_request.number }}
cancel-in-progress: true
env:
# https://github.com/docker/buildx/releases/tag/v0.39.1
BUILDX_VERSION: v0.39.1
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|src/upstream\.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 tested image
uses: actions/download-artifact@v8.0.2
with:
name: image-latest
path: ${{ runner.temp }}/image
- name: Log in to ghcr.io
uses: docker/login-action@v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Buildx
uses: docker/setup-buildx-action@v4.4.1
with:
version: ${{ env.BUILDX_VERSION }}
driver: docker
cache-binary: false
- name: Push the image of the pull request
env:
TAG: pr-${{ github.event.pull_request.number }}
run: |
digest="$(jq -r '.manifests[0].digest' "$RUNNER_TEMP/image/index.json")"
docker buildx imagetools create --prefer-index=false --tag "ghcr.io/peakimages/sqlite:$TAG" "oci-layout://$RUNNER_TEMP/image@$digest"
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 tested images
uses: actions/download-artifact@v8.0.2
with:
pattern: image-latest-*
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" ghcr.io/peakimages/sqlite: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