|
| 1 | +name: Cache Fsync |
| 2 | +on: |
| 3 | + merge_group: |
| 4 | + schedule: |
| 5 | + - cron: "45 2 * * *" # 0245 UTC everyday |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + IMAGE_NAME: fsync |
| 10 | + IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref || github.run_id }}-${{ inputs.fedora_version }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: fsync |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + packages: write |
| 23 | + id-token: write |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + fedora_version: |
| 28 | + - 39 |
| 29 | + - 40 |
| 30 | + steps: |
| 31 | + - name: Checkout Push to Registry action |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Verify Akmods Image |
| 35 | + uses: EyeCantCU/cosign-action/verify@v0.2.2 |
| 36 | + with: |
| 37 | + containers: akmods:fsync-40 |
| 38 | + pubkey: https://raw.githubusercontent.com/ublue-os/akmods/main/cosign.pub |
| 39 | + registry: ghcr.io/ublue-os |
| 40 | + |
| 41 | + - name: Get Fsync Kernel Version |
| 42 | + id: Version |
| 43 | + uses: Wandalen/wretry.action@v3.5.0 |
| 44 | + with: |
| 45 | + attempt_limit: 3 |
| 46 | + attempt_delay: 15000 |
| 47 | + command: | |
| 48 | + kernel_release=$(skopeo inspect docker://ghcr.io/ublue-os/akmods:fsync-40 | jq -r '.Labels["ostree.linux"] | split(".fc")[0]') |
| 49 | + major=$(echo "$kernel_release" | cut -d '.' -f 1) |
| 50 | + minor=$(echo "$kernel_release" | cut -d '.' -f 2) |
| 51 | + patch=$(echo "$kernel_release" | cut -d '.' -f 3) |
| 52 | + kernel_major_minor_patch="${major}.${minor}.${patch}" |
| 53 | + ver=$(skopeo inspect docker://quay.io/fedora-ostree-desktops/base:${{ matrix.fedora_version }} | jq -r '.Labels["org.opencontainers.image.version"]') |
| 54 | + if [ -z "$ver" ] || [ "null" = "$ver" ]; then |
| 55 | + echo "inspected image version must not be empty or null" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + echo "version=$ver" >> $GITHUB_ENV |
| 59 | + echo "kernel_release=${kernel_release}" >> $GITHUB_ENV |
| 60 | + echo "kernel_major_minor_patch=${kernel_major_minor_patch}" >> $GITHUB_ENV |
| 61 | +
|
| 62 | + - name: Checkout Push to Registry Action |
| 63 | + uses: actions/checkout@v4 |
| 64 | + |
| 65 | + - name: Generate Tags |
| 66 | + id: generate_tags |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + tag="${{ env.kernel_major_minor_patch }}.fsync.fc${{ matrix.fedora_version }}.x86_64" |
| 70 | + COMMIT_TAGS=() |
| 71 | + COMMIT_TAGS+=("pr-${{ github.event_number }}-${tag}") |
| 72 | + COMMIT_TAGS+=("${GITHUB_SHA::7}-${tag}") |
| 73 | +
|
| 74 | + BUILD_TAG=(${tag}) |
| 75 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 76 | + echo "Generated the following commit tags: " |
| 77 | + for TAG in "${COMMIT_TAGS[@]}"; do |
| 78 | + echo "${TAG}" |
| 79 | + done |
| 80 | +
|
| 81 | + alias_tags=("${COMMIT_TAGS[@]}") |
| 82 | + else |
| 83 | + alias_tags=("${BUILD_TAG[@]}") |
| 84 | + fi |
| 85 | +
|
| 86 | + echo "Generated the following build tags: " |
| 87 | + for TAG in "${alias_tags[@]}"; do |
| 88 | + echo "${TAG}" |
| 89 | + done |
| 90 | +
|
| 91 | + echo "alias_tags=${alias_tags[*]}" >> $GITHUB_OUTPUT |
| 92 | +
|
| 93 | + - name: Pull Image |
| 94 | + uses: Wandalen/wretry.action@v3.5.0 |
| 95 | + with: |
| 96 | + attempt_limit: 3 |
| 97 | + attempt_delay: 15000 |
| 98 | + command: | |
| 99 | + podman pull quay.io/fedora-ostree-desktops/base:${{ matrix.fedora_version }} |
| 100 | +
|
| 101 | + - name: Build Metadata |
| 102 | + uses: docker/metadata-action@v5 |
| 103 | + id: meta |
| 104 | + with: |
| 105 | + images: | |
| 106 | + ${{ env.IMAGE_NAME }} |
| 107 | + labels: | |
| 108 | + org.opencontainers.image.title=${{ env.IMAGE_NAME }} |
| 109 | + org.opencontainers.image.description=A caching layer for sentry/kernel-fsync fsync kernel's |
| 110 | + org.opencontainers.image.version=${{ env.version }} |
| 111 | + ostree.linux="${{ env.kernel_major_minor_patch }}.fc${{ matrix.fedora_version }}.x86_64" |
| 112 | + io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/main/README.md |
| 113 | + io.artifacthub.package.logo-url=https://avatars.githubusercontent.com/u/1728152?s=200&v=4 |
| 114 | +
|
| 115 | + - name: Build Image |
| 116 | + id: build_image |
| 117 | + uses: redhat-actions/buildah-build@v2 |
| 118 | + with: |
| 119 | + containerfiles: | |
| 120 | + ./Containerfile |
| 121 | + image: ${{ env.IMAGE_NAME }} |
| 122 | + tags: ${{ steps.generate_tags.outputs.alias_tags }} |
| 123 | + build-args: | |
| 124 | + FEDORA_VERSION=${{ matrix.fedora_version }} |
| 125 | + KERNEL_VERSION=${{ env.kernel_major_minor_patch }} |
| 126 | + labels: ${{ steps.meta.outputs.labels }} |
| 127 | + oci: false |
| 128 | + |
| 129 | + - name: Lowercase Registry |
| 130 | + id: registry_case |
| 131 | + uses: ASzc/change-string-case-action@v6 |
| 132 | + with: |
| 133 | + string: ${{ env.IMAGE_REGISTRY }} |
| 134 | + |
| 135 | + - name: Push to GHCR |
| 136 | + uses: Wandalen/wretry.action@v3.5.0 |
| 137 | + id: push |
| 138 | + if: github.event_name != 'pull_request' |
| 139 | + env: |
| 140 | + REGISTRY_USER: ${{ github.actor }} |
| 141 | + REGISTRY_PASSWORD: ${{ github.token }} |
| 142 | + with: |
| 143 | + action: redhat-actions/push-to-registry@v2 |
| 144 | + attempt_limit: 3 |
| 145 | + attempt_delay: 15000 |
| 146 | + with: | |
| 147 | + image: ${{ steps.build_image.outputs.image }} |
| 148 | + tags: ${{ steps.build_image.outputs.tags }} |
| 149 | + registry: ${{ steps.registry_case.outputs.lowercase }} |
| 150 | + username: ${{ env.REGISTRY_USER }} |
| 151 | + password: ${{ env.REGISTRY_PASSWORD }} |
| 152 | + extra-args: | |
| 153 | + --disable-content-trust |
| 154 | + - name: Login to GitHub Container Registry |
| 155 | + uses: docker/login-action@v3 |
| 156 | + if: github.event_name != 'pull_request' |
| 157 | + with: |
| 158 | + registry: ghcr.io |
| 159 | + username: ${{ github.actor }} |
| 160 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 161 | + |
| 162 | + # Sign container |
| 163 | + - uses: sigstore/cosign-installer@v3.5.0 |
| 164 | + if: github.event_name != 'pull_request' |
| 165 | + |
| 166 | + - name: Sign container image |
| 167 | + if: github.event_name != 'pull_request' |
| 168 | + run: | |
| 169 | + cosign sign -y --key env://COSIGN_PRIVATE_KEY ${{ steps.registry_case.outputs.lowercase }}/${{ steps.build_image.outputs.image }}@${TAGS} |
| 170 | + env: |
| 171 | + TAGS: ${{ steps.push.outputs.outputs && fromJSON(steps.push.outputs.outputs).digest }} |
| 172 | + COSIGN_EXPERIMENTAL: false |
| 173 | + COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }} |
| 174 | + |
| 175 | + - name: Echo outputs |
| 176 | + if: github.event_name != 'pull_request' |
| 177 | + run: | |
| 178 | + echo "${{ toJSON(steps.push.outputs) }}" |
| 179 | +
|
| 180 | + check: |
| 181 | + name: Check all builds successful |
| 182 | + runs-on: ubuntu-latest |
| 183 | + needs: [build] |
| 184 | + steps: |
| 185 | + - name: Exit on failure |
| 186 | + if: ${{ needs.build.result == 'failure' }} |
| 187 | + shell: bash |
| 188 | + run: exit 1 |
| 189 | + - name: Exit |
| 190 | + shell: bash |
| 191 | + run: exit 0 |
0 commit comments