Skip to content

Commit 7864c78

Browse files
authored
[GHA] Add workflow to build container for operational metrics (#484)
Add a GItHub Action workflow that builds the operational metrics container defined in `llvm-ops-metrics/ops-container` (#483) and pushes it to the GitHub container registry. This container scrapes [llvm-project](https://github.com/llvm/llvm-project) for new commits & their associated reviews at a daily cadence and exports that data to Grafana for visualization. This workflow definition closely follows the workflow for building the [premerge metrics container in llvm-project](https://github.com/llvm/llvm-project/blob/main/.github/workflows/build-metrics-container.yml)
1 parent 9e8c5a4 commit 7864c78

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build Operations Metrics Container
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- .github/workflows/build-operations-metrics-container.yml
12+
- 'llvm-ops-metrics/ops-container/**'
13+
pull_request:
14+
branches:
15+
- main
16+
paths:
17+
- .github/workflows/build-operations-metrics-container.yml
18+
- '.llvm-ops-metrics/ops-container/**'
19+
20+
jobs:
21+
build-operations-metrics-container:
22+
if: github.repository_owner == 'llvm'
23+
runs-on: ubuntu-24.04
24+
outputs:
25+
container-name: ${{ steps.vars.outputs.container-name }}
26+
container-name-tag: ${{ steps.vars.outputs.container-name-tag }}
27+
container-filename: ${{ steps.vars.outputs.container-filename }}
28+
steps:
29+
- name: Checkout LLVM Zorg
30+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
31+
with:
32+
sparse-checkout: llvm-ops-metrics/ops-container
33+
- name: Write Variables
34+
id: vars
35+
run: |
36+
tag=`date +%s`
37+
container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/operations-metrics"
38+
echo "container-name=$container_name" >> $GITHUB_OUTPUT
39+
echo "container-name-tag=$container_name:$tag" >> $GITHUB_OUTPUT
40+
echo "container-filename=$(echo $container_name:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
41+
- name: Build Container
42+
working-directory: ./llvm-ops-metrics/ops-container
43+
run: |
44+
podman build -t ${{ steps.vars.outputs.container-name-tag }} -f Dockerfile .
45+
# Save the container so we have it in case the push fails. This also
46+
# allows us to separate the push step into a different job so we can
47+
# maintain minimal permissions while building the container.
48+
- name: Save Container Image
49+
run: |
50+
podman save ${{ steps.vars.outputs.container-name-tag }} > ${{ steps.vars.outputs.container-filename }}
51+
- name: Upload Container Image
52+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
53+
with:
54+
name: container
55+
path: ${{ steps.vars.outputs.container-filename }}
56+
retention-days: 14
57+
58+
push-metrics-container:
59+
if: github.event_name == 'push'
60+
needs:
61+
- build-operations-metrics-container
62+
permissions:
63+
packages: write
64+
runs-on: ubuntu-24.04
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
steps:
68+
- name: Download Container Image
69+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
70+
with:
71+
name: container
72+
- name: Push Container
73+
run: |
74+
podman load -i ${{ needs.build-operations-metrics-container.outputs.container-filename }}
75+
podman tag ${{ needs.build-operations-metrics-container.outputs.container-name-tag }} ${{ needs.build-operations-metrics-container.outputs.container-name }}:latest
76+
podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io
77+
podman push ${{ needs.build-operations-metrics-container.outputs.container-name-tag }}
78+
podman push ${{ needs.build-operations-metrics-container.outputs.container-name }}:latest
79+

0 commit comments

Comments
 (0)