|
| 1 | +name: build-ublue |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + pull_request_review: |
| 5 | + type: [submitted] |
| 6 | + merge_group: |
| 7 | + schedule: |
| 8 | + - cron: '0 7 * * *' # 7 am everyday |
| 9 | + workflow_dispatch: |
| 10 | +env: |
| 11 | + IMAGE_BASE_NAME: main |
| 12 | + IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} |
| 13 | + |
| 14 | +jobs: |
| 15 | + push-ghcr: |
| 16 | + name: Build and push image |
| 17 | + if: github.event.review.state == 'approved' || github.event_name != 'pull_request_review' |
| 18 | + runs-on: ubuntu-22.04 |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + id-token: write |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + image_name: [silverblue, kinoite, vauxite, sericea, base, lxqt, mate] |
| 27 | + major_version: [37, 38] |
| 28 | + include: |
| 29 | + - major_version: 37 |
| 30 | + is_latest_version: false |
| 31 | + is_stable_version: true |
| 32 | + - major_version: 38 |
| 33 | + is_latest_version: true |
| 34 | + is_stable_version: true |
| 35 | + exclude: |
| 36 | + # There is no Fedora 37 version of sericea |
| 37 | + # When F38 is added, sericea will automatically be built too |
| 38 | + - image_name: sericea |
| 39 | + major_version: 37 |
| 40 | + steps: |
| 41 | + - name: Delete image |
| 42 | + uses: bots-house/ [email protected] |
| 43 | + with: |
| 44 | + # NOTE: at now only orgs is supported |
| 45 | + owner: bots-house |
| 46 | + name: some-web-service |
| 47 | + # NOTE: using Personal Access Token |
| 48 | + token: ${{ secrets.PAT }} |
| 49 | + tag: pr-${{github.event.pull_request.number}} |
| 50 | + run: |
| 51 | + |
| 52 | + # Checkout push-to-registry action GitHub repository |
| 53 | + - name: Checkout Push to Registry action |
| 54 | + uses: actions/checkout@v3 |
| 55 | + |
| 56 | + - name: Matrix Variables |
| 57 | + run: | |
| 58 | + if [[ "${{ matrix.image_name }}" == "lxqt" || "${{ matrix.image_name }}" == "mate" ]]; then |
| 59 | + echo "SOURCE_IMAGE=base" >> $GITHUB_ENV |
| 60 | + else |
| 61 | + echo "SOURCE_IMAGE=${{ matrix.image_name }}" >> $GITHUB_ENV |
| 62 | + fi |
| 63 | + echo "IMAGE_NAME=${{ format('{0}-{1}', matrix.image_name, env.IMAGE_BASE_NAME) }}" >> $GITHUB_ENV |
| 64 | + |
| 65 | + - name: Generate tags |
| 66 | + id: generate-tags |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + # Generate a timestamp for creating an image version history |
| 70 | + TIMESTAMP="$(date +%Y%m%d)" |
| 71 | + MAJOR_VERSION="${{ matrix.major_version }}" |
| 72 | + COMMIT_TAGS=() |
| 73 | + BUILD_TAGS=() |
| 74 | + # Have tags for tracking builds during pull request |
| 75 | + SHA_SHORT="${GITHUB_SHA::7}" |
| 76 | + COMMIT_TAGS+=("pr-${{ github.event.pull_request.number }}-${MAJOR_VERSION}") |
| 77 | + COMMIT_TAGS+=("${SHA_SHORT}-${MAJOR_VERSION}") |
| 78 | + if [[ "${{ matrix.is_latest_version }}" == "true" ]] && \ |
| 79 | + [[ "${{ matrix.is_stable_version }}" == "true" ]]; then |
| 80 | + COMMIT_TAGS+=("pr-${{ github.event.pull_request.number }}") |
| 81 | + COMMIT_TAGS+=("${SHA_SHORT}") |
| 82 | + fi |
| 83 | + |
| 84 | + BUILD_TAGS=("${MAJOR_VERSION}" "${MAJOR_VERSION}-${TIMESTAMP}") |
| 85 | + |
| 86 | + if [[ "${{ matrix.is_latest_version }}" == "true" ]] && \ |
| 87 | + [[ "${{ matrix.is_stable_version }}" == "true" ]]; then |
| 88 | + BUILD_TAGS+=("latest") |
| 89 | + fi |
| 90 | + |
| 91 | + if [[ "${{ github.event_name }}" == "pull_request_review" ]]; then |
| 92 | + echo "Generated the following commit tags: " |
| 93 | + for TAG in "${COMMIT_TAGS[@]}"; do |
| 94 | + echo "${TAG}" |
| 95 | + done |
| 96 | + alias_tags=("${COMMIT_TAGS[@]}") |
| 97 | + else |
| 98 | + alias_tags=("${BUILD_TAGS[@]}") |
| 99 | + fi |
| 100 | + echo "Generated the following build tags: " |
| 101 | + for TAG in "${BUILD_TAGS[@]}"; do |
| 102 | + echo "${TAG}" |
| 103 | + done |
| 104 | + echo "alias_tags=${alias_tags[*]}" >> $GITHUB_OUTPUT |
| 105 | + |
| 106 | + - name: Get current version |
| 107 | + id: labels |
| 108 | + run: | |
| 109 | + ver=$(skopeo inspect docker://quay.io/fedora-ostree-desktops/${{ env.SOURCE_IMAGE }}:${{ matrix.major_version }} | jq -r '.Labels["org.opencontainers.image.version"]') |
| 110 | + echo "VERSION=$ver" >> $GITHUB_OUTPUT |
| 111 | + |
| 112 | + # Build metadata |
| 113 | + - name: Image Metadata |
| 114 | + uses: docker/metadata-action@v4 |
| 115 | + id: meta |
| 116 | + with: |
| 117 | + images: | |
| 118 | + ${{ env.IMAGE_NAME }} |
| 119 | + labels: | |
| 120 | + org.opencontainers.image.title=${{ env.IMAGE_NAME }} |
| 121 | + org.opencontainers.image.version=${{ steps.labels.outputs.VERSION }} |
| 122 | + org.opencontainers.image.description=A base ${{ env.IMAGE_NAME }} image with batteries included |
| 123 | + io.artifacthub.package.readme-url=https://raw.githubusercontent.com/ublue-os/main/main/README.md |
| 124 | + io.artifacthub.package.logo-url=https://avatars.githubusercontent.com/u/120078124?s=200&v=4 |
| 125 | + |
| 126 | + # Build image using Buildah action |
| 127 | + - name: Build Image |
| 128 | + id: build_image |
| 129 | + uses: redhat-actions/buildah-build@v2 |
| 130 | + with: |
| 131 | + containerfiles: | |
| 132 | + ./Containerfile |
| 133 | + image: ${{ env.IMAGE_NAME }} |
| 134 | + tags: | |
| 135 | + ${{ steps.generate-tags.outputs.alias_tags }} |
| 136 | + build-args: | |
| 137 | + IMAGE_NAME=${{ matrix.image_name }} |
| 138 | + SOURCE_IMAGE=${{ env.SOURCE_IMAGE }} |
| 139 | + FEDORA_MAJOR_VERSION=${{ matrix.major_version }} |
| 140 | + labels: ${{ steps.meta.outputs.labels }} |
| 141 | + oci: false |
| 142 | + |
| 143 | + # Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR. |
| 144 | + # https://github.com/macbre/push-to-ghcr/issues/12 |
| 145 | + - name: Lowercase Registry |
| 146 | + id: registry_case |
| 147 | + uses: ASzc/change-string-case-action@v5 |
| 148 | + with: |
| 149 | + string: ${{ env.IMAGE_REGISTRY }} |
| 150 | + |
| 151 | + # Push the image to GHCR (Image Registry) |
| 152 | + - name: Push To GHCR |
| 153 | + uses: redhat-actions/push-to-registry@v2 |
| 154 | + id: push |
| 155 | + if: github.event.review.state == 'approved' || github.event_name != 'pull_request' |
| 156 | + env: |
| 157 | + REGISTRY_USER: ${{ github.actor }} |
| 158 | + REGISTRY_PASSWORD: ${{ github.token }} |
| 159 | + with: |
| 160 | + image: ${{ steps.build_image.outputs.image }} |
| 161 | + tags: ${{ steps.build_image.outputs.tags }} |
| 162 | + registry: ${{ steps.registry_case.outputs.lowercase }} |
| 163 | + username: ${{ env.REGISTRY_USER }} |
| 164 | + password: ${{ env.REGISTRY_PASSWORD }} |
| 165 | + extra-args: | |
| 166 | + --disable-content-trust |
| 167 | + |
| 168 | + - name: Login to GitHub Container Registry |
| 169 | + uses: docker/login-action@v2 |
| 170 | + if: github.event.review.state == 'approved' || github.event_name != 'pull_request' |
| 171 | + with: |
| 172 | + registry: ghcr.io |
| 173 | + username: ${{ github.actor }} |
| 174 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 175 | + |
| 176 | + # Sign container |
| 177 | + - uses: sigstore/ [email protected] |
| 178 | + if: github.event.review.state == 'approved' || github.event_name != 'pull_request' |
| 179 | + |
| 180 | + - name: Sign container image |
| 181 | + if: github.event.review.state == 'approved' || github.event_name != 'pull_request' |
| 182 | + run: | |
| 183 | + cosign sign -y --key env://COSIGN_PRIVATE_KEY ${{ steps.registry_case.outputs.lowercase }}/${{ env.IMAGE_NAME }}@${TAGS} |
| 184 | + env: |
| 185 | + TAGS: ${{ steps.push.outputs.digest }} |
| 186 | + COSIGN_EXPERIMENTAL: false |
| 187 | + COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }} |
| 188 | + |
| 189 | + - name: Echo outputs |
| 190 | + if: github.event.review.state == 'approved' || github.event_name != 'pull_request' |
| 191 | + run: | |
| 192 | + echo "${{ toJSON(steps.push.outputs) }}" |
0 commit comments