[IRBuilder] Refactor FMF interface (#121657)
[llvm-project.git] / .github / workflows / build-metrics-container.yml
blob751ab679411dcbd1009a0a39b7041c66d1248669
1 name: Build Metrics Container
3 permissions:
4   contents: read
6 on:
7   push:
8     branches:
9       - main
10     paths:
11       - .github/workflows/build-metrics-container.yml
12       - '.ci/metrics/**'
13   pull_request:
14     branches:
15       - main
16     paths:
17       - .github/workflows/build-metrics-container.yml
18       - '.ci/metrics/**'
20 jobs:
21   build-metrics-container:
22     if: github.repository_owner == 'llvm'
23     runs-on: ubuntu-latest
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
30         uses: actions/checkout@v4
31         with:
32           sparse-checkout: .ci/metrics/
33       - name: Write Variables
34         id: vars
35         run: |
36           tag=`date +%s`
37           container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/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: ./.ci/metrics
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@v4
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-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
69         uses: actions/download-artifact@v4
70         with:
71           name: container
72       - name: Push Container
73         run: |
74           podman load -i ${{ needs.build-metrics-container.outputs.container-filename }}
75           podman tag ${{ needs.build-metrics-container.outputs.container-name-tag }} ${{ needs.build-metrics-container.outputs.container-name }}:latest
76           podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io
77           podman push ${{ needs.build-metrics-container.outputs.container-name-tag }}
78           podman push ${{ needs.build-metrics-container.outputs.container-name }}:latest