-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (137 loc) · 5.38 KB
/
Copy pathimage-github-runner-ci.yml
File metadata and controls
148 lines (137 loc) · 5.38 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
142
143
144
145
146
147
148
---
name: Build GitHub Runner CI Image
on: # yamllint disable-line rule:truthy
push:
branches:
- main
paths:
- .github/workflows/image-github-runner-ci.yml
- images/github-runner-ci/**
tags:
- github-runner-ci-*
pull_request:
branches:
- main
paths:
- .github/workflows/image-github-runner-ci.yml
- images/github-runner-ci/**
jobs:
build-github-runner-ci:
name: Build GitHub Runner CI Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.build.outputs.digest }}
run_job_container_test: ${{ steps.image_export.outputs.push }}
tag: ${{ steps.version_tag.outputs.tag }}
steps:
- name: Checkout Repo
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Login to GitHub Container Registry
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute Version Tag
env:
BRANCH: ${{ github.ref_type == 'tag' && github.ref_name || github.event_name != 'pull_request' && format('{0}.{1}.{2}', github.run_id, github.run_number, github.run_attempt) || format('pr-{0}.{1}.{2}.{3}', github.event.number, github.run_id, github.run_number, github.run_attempt) }}
id: version_tag
run: echo "tag=$BRANCH" | sed -e 's/github-runner-ci-//' >> "$GITHUB_OUTPUT"
- name: Select Image Export Mode
id: image_export
env:
HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" && "${HEAD_REPOSITORY}" != "${GITHUB_REPOSITORY}" ]]; then
echo "load=true" >> "$GITHUB_OUTPUT"
echo "push=false" >> "$GITHUB_OUTPUT"
else
echo "load=false" >> "$GITHUB_OUTPUT"
echo "push=true" >> "$GITHUB_OUTPUT"
fi
- name: Generate Metadata
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
id: metadata
with:
images: ghcr.io/${{ github.repository_owner }}/github-runner-ci
- name: Build Image
id: build
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: images/github-runner-ci
file: images/github-runner-ci/Containerfile
labels: ${{ steps.metadata.outputs.labels }}
load: ${{ steps.image_export.outputs.load }}
push: ${{ steps.image_export.outputs.push }}
tags: ghcr.io/${{ github.repository_owner }}/github-runner-ci:${{ steps.version_tag.outputs.tag }}
- name: Smoke Test Image
run: |
docker run --rm ghcr.io/${{ github.repository_owner }}/github-runner-ci:${{ steps.version_tag.outputs.tag }} bash -lc '
test "$(id -u):$(id -g)" = "1001:1001"
test "$HOME" = "/home/runner"
test -w "$HOME"
test -w "$HOME/.local"
test -w "$HOME/.local/bin"
test -w "$HOME/.local/share"
brew --version
git --version
just --version
jq --version
rg --version
shellcheck --version
yq --version
'
test-github-actions-job-container:
name: Test GitHub Actions Job Container
needs: build-github-runner-ci
if: ${{ needs.build-github-runner-ci.outputs.run_job_container_test == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
container:
image: ghcr.io/${{ github.repository_owner }}/github-runner-ci@${{ needs.build-github-runner-ci.outputs.digest }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout Repo
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Verify Actions Job Container
shell: bash
run: |
set -euo pipefail
echo "uid_gid=$(id -u):$(id -g)"
echo "user=$(id -un):$(id -gn)"
echo "HOME=${HOME}"
echo "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}"
echo "RUNNER_TEMP=${RUNNER_TEMP}"
test "${GITHUB_ACTIONS}" = "true"
test "$(id -u):$(id -g)" = "1001:1001"
test "$(id -un):$(id -gn)" = "runner:runner"
test -w "${HOME}"
mkdir -p "${HOME}/.local/bin" "${HOME}/.local/share"
test -w "${HOME}/.local/bin"
test -w "${HOME}/.local/share"
test -w "${GITHUB_WORKSPACE}"
test -w "${RUNNER_TEMP}"
brew --version
brew install hello
brew list --versions hello
hello --version
touch "${GITHUB_WORKSPACE}/.github-runner-ci-write-test"
rm "${GITHUB_WORKSPACE}/.github-runner-ci-write-test"
printf 'github-runner-ci job container test\n' > "${RUNNER_TEMP}/github-runner-ci.txt"
test -f "${GITHUB_WORKSPACE}/justfile"
test "$(git -C "${GITHUB_WORKSPACE}" rev-parse --is-inside-work-tree)" = "true"
git -C "${GITHUB_WORKSPACE}" status --short
git --version
just --version
jq --version
rg --version
shellcheck --version
yq --version