Skip to content

Commit b543462

Browse files
committed
feat: Build and use container with rpmlint preinstalled
Based on Fedora minimal
1 parent c5d3243 commit b543462

File tree

4 files changed

+133
-4
lines changed

4 files changed

+133
-4
lines changed

.github/workflows/build.yml

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Build rpmlint container
2+
on:
3+
schedule:
4+
- cron: '00 07 * * *'
5+
workflow_dispatch:
6+
env:
7+
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
8+
9+
jobs:
10+
push-ghcr:
11+
name: Build
12+
runs-on: ubuntu-22.04
13+
permissions:
14+
contents: read
15+
packages: write
16+
id-token: write
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
image_name: [rpmlint-action]
21+
steps:
22+
# Checkout push-to-registry action GitHub repository
23+
- name: Checkout Push to Registry action
24+
uses: actions/checkout@v4
25+
26+
- name: Generate tags
27+
id: generate-tags
28+
shell: bash
29+
run: |
30+
# Generate a timestamp for creating an image version history
31+
TIMESTAMP="$(date +%Y%m%d)"
32+
COMMIT_TAGS=()
33+
BUILD_TAGS=()
34+
# Have tags for tracking builds during pull request
35+
SHA_SHORT="${GITHUB_SHA::7}"
36+
COMMIT_TAGS+=("pr-${{ github.event.pull_request.number }}")
37+
COMMIT_TAGS+=("${SHA_SHORT}")
38+
39+
BUILD_TAGS=("latest" "${TIMESTAMP}")
40+
41+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
42+
echo "Generated the following commit tags: "
43+
for TAG in "${COMMIT_TAGS[@]}"; do
44+
echo "${TAG}"
45+
done
46+
alias_tags=("${COMMIT_TAGS[@]}")
47+
else
48+
alias_tags=("${BUILD_TAGS[@]}")
49+
fi
50+
echo "Generated the following build tags: "
51+
for TAG in "${BUILD_TAGS[@]}"; do
52+
echo "${TAG}"
53+
done
54+
echo "alias_tags=${alias_tags[*]}" >> $GITHUB_OUTPUT
55+
56+
# Build metadata
57+
- name: Image Metadata
58+
uses: docker/metadata-action@v5
59+
id: meta
60+
with:
61+
images: |
62+
${{ matrix.image_name }}
63+
labels: |
64+
org.opencontainers.image.title=${{ matrix.image_name }}
65+
org.opencontainers.image.version=latest
66+
org.opencontainers.image.description=Test Actions.
67+
io.artifacthub.package.readme-url=https://github.com/${{ github.repository_owner }}/rpmlint-action#readme
68+
69+
# Build image using Buildah action
70+
- name: Build Image
71+
id: build_image
72+
uses: redhat-actions/buildah-build@v2
73+
with:
74+
containerfiles: |
75+
./container/Containerfile
76+
image: ${{ matrix.image_name }}
77+
tags: |
78+
${{ steps.generate-tags.outputs.alias_tags }}
79+
labels: ${{ steps.meta.outputs.labels }}
80+
oci: true
81+
extra-args: |
82+
--target=${{ matrix.image_name }}
83+
84+
# Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR.
85+
# https://github.com/macbre/push-to-ghcr/issues/12
86+
- name: Lowercase Registry
87+
id: registry_case
88+
uses: ASzc/change-string-case-action@v5
89+
with:
90+
string: ${{ env.IMAGE_REGISTRY }}
91+
92+
# Push the image to GHCR (Image Registry)
93+
- name: Push To GHCR
94+
uses: redhat-actions/push-to-registry@v2
95+
id: push
96+
if: github.event_name != 'pull_request'
97+
env:
98+
REGISTRY_USER: ${{ github.actor }}
99+
REGISTRY_PASSWORD: ${{ github.token }}
100+
with:
101+
image: ${{ steps.build_image.outputs.image }}
102+
tags: ${{ steps.build_image.outputs.tags }}
103+
registry: ${{ steps.registry_case.outputs.lowercase }}
104+
username: ${{ env.REGISTRY_USER }}
105+
password: ${{ env.REGISTRY_PASSWORD }}
106+
extra-args: |
107+
--disable-content-trust
108+
109+
- name: Sign image
110+
uses: EyeCantCU/cosign-action/sign@v0.1.2
111+
with:
112+
container: ghcr.io/${{ github.repository_owner }}/${{ matrix.image_name }}
113+
registry-token: ${{ secrets.GITHUB_TOKEN }}
114+
signing-secret: ${{ secrets.SIGNING_SECRET }}
115+
tags: ${{ steps.push.outputs.digest }}
116+
117+
- name: Echo outputs
118+
if: github.event_name != 'pull_request'
119+
run: |
120+
echo "${{ toJSON(steps.push.outputs) }}"
121+
122+
check:
123+
name: Check all builds successful
124+
runs-on: ubuntu-latest
125+
needs: [push-ghcr]
126+
steps:
127+
- name: Exit
128+
shell: bash
129+
run: exit 0

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM quay.io/fedora/fedora-minimal:39
1+
FROM ghcr.io/eyecantcu/rpmlint-action:latest
22

33
COPY rpmlint.sh /tmp/rpmlint.sh
44

container/Containerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM quay.io/fedora/fedora-minimal:39 AS rpmlint-action
2+
3+
RUN dnf5 install -y rpmlint

rpmlint.sh

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/usr/bin/bash
22

3-
# Install rpmlint
4-
dnf5 install -qy rpmlint > /dev/null
5-
63
# Parse arguments
74
ARGUMENTS=""
85
if [[ -n "${HELP}" ]]; then ARGUMENTS+=" -h "; fi

0 commit comments

Comments
 (0)