forked from TraceMachina/nativelink
-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (123 loc) · 4.63 KB
/
custom-image.yaml
File metadata and controls
141 lines (123 loc) · 4.63 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Build Custom Docker Image
on:
workflow_dispatch:
inputs:
image:
description: 'Image to build'
required: false
default: 'image'
type: choice
options:
- image
- nativelink-worker-init
- nativelink-worker-lre-cc
skip_signing:
description: 'Skip cosign signing'
required: false
default: true
type: boolean
issue_comment:
types: [created]
permissions:
contents: read
packages: write
pull-requests: write
id-token: write
jobs:
check-trigger:
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.check.outputs.should_build }}
pr_sha: ${{ steps.check.outputs.pr_sha }}
image: ${{ steps.check.outputs.image }}
steps:
- name: Check trigger
id: check
uses: actions/github-script@v8
with:
script: |
if (context.eventName === 'workflow_dispatch') {
core.setOutput('should_build', 'true');
core.setOutput('pr_sha', context.sha);
core.setOutput('image', '${{ inputs.image }}');
return;
}
if (context.eventName === 'issue_comment') {
const body = context.payload.comment.body.trim();
const isPR = !!context.payload.issue.pull_request;
// Match /build-image or /build-image <image-name>
const match = body.match(/^\/build-image(?:\s+(\S+))?/i);
if (isPR && match) {
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.issue.number
});
const image = match[1] || 'image';
const validImages = ['image', 'nativelink-worker-init', 'nativelink-worker-lre-cc'];
if (!validImages.includes(image)) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: `Unknown image: \`${image}\`\n\nValid options: ${validImages.map(i => `\`${i}\``).join(', ')}`
});
core.setOutput('should_build', 'false');
return;
}
core.setOutput('should_build', 'true');
core.setOutput('pr_sha', pr.head.sha);
core.setOutput('image', image);
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});
return;
}
}
core.setOutput('should_build', 'false');
build-image:
name: Build and Push Image
needs: check-trigger
if: needs.check-trigger.outputs.should_build == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ needs.check-trigger.outputs.pr_sha }}
- name: Prepare Worker
uses: ./.github/actions/prepare-nix
- name: Upload image
id: upload
run: |
GIT_HASH=$(git rev-parse --short HEAD)
nix run .#publish-ghcr ${{ needs.check-trigger.outputs.image }} "$GIT_HASH"
IMAGE_NAME=$(nix eval .#${{ needs.check-trigger.outputs.image }}.imageName --raw)
echo "image_tag=ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}:${GIT_HASH}" >> $GITHUB_OUTPUT
env:
GHCR_REGISTRY: ghcr.io/${{ github.repository_owner }}
GHCR_USERNAME: ${{ github.actor }}
GHCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
SKIP_SIGNING: "true"
SKIP_TRIVY: "true"
- name: Output image info
run: |
echo "### Published Image" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "${{ steps.upload.outputs.image_tag }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Comment on PR
if: github.event_name == 'issue_comment'
uses: actions/github-script@v8
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: `Image built and pushed!\n\n\`\`\`\n${{ steps.upload.outputs.image_tag }}\n\`\`\``
});