Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Dec 28, 2023
1 parent cedac14 commit 69a0117
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
45 changes: 26 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Docker images
run-name: Images CI for "${{ inputs.base_image_tags || github.event.client_payload.base_image_tags }}"${{ github.event.client_payload.git_ref && ' at ' + github.event.client_payload.git_ref || '' }}
run-name: Images CI for "${{ inputs.base_image_tags || github.event.client_payload.base_image_tags }}"${{ github.event.client_payload.git_ref && format(' at {0}', github.event.client_payload.git_ref) || '' }}

on:
workflow_dispatch:
Expand All @@ -16,61 +16,69 @@ on:

jobs:
config:
name: Build matrix from input
name: Build config
runs-on: ubuntu-latest

steps:
- name: Build matrix
id: config
- id: config
uses: actions/github-script@v7
with:
script: |
let input_tags = process.env.BASE_IMAGE_TAGS_WD || process.env.BASE_IMAGE_TAGS_RD
console.log(`Input raw tags: ${input_tags}`)
let tags = input_tags.split(',').filter(tag => tag !== '')
if (tags.length == 0) {
let base_image_tags = input_tags.split(',').filter(tag => tag !== '')
if (base_image_tags.length == 0) {
core.setFailed("no valid base image tag")
return
}
let tagsMultiline = tags.join('\n')
core.setOutput('tag', tags[0])
core.setOutput('tags', tagsMultiline)
let tagsMultiline = base_image_tags.join('\n')
core.setOutput('base_image_tag', base_image_tags[0])
core.setOutput('base_image_tags', tagsMultiline)
core.summary.addHeading('Input tags').addCodeBlock(tagsMultiline).write()
console.log('base_image_tags:')
base_image_tags.forEach(tag => console.log(`- ${tag}`))
function expr(s) {
let ret = '$' + '{{ ' + s;
return ret + ' }}'
}
openjdk_tags = []
tags.forEach(tag => {
openjdk_tags.push(`type=raw,value=${tag}` + ",enable=${{ matrix.extra == 'false' && matrix.java == '17' }}")
openjdk_tags.push(`type=raw,value=${tag}` + "-extra,enable=${{ matrix.extra == 'true' && matrix.java == '17' }}")
openjdk_tags.push(`type=raw,value=${tag}` + "-jdk${{ matrix.java }},enable=${{ matrix.extra == 'false' }}")
openjdk_tags.push(`type=raw,value=${tag}` + "-jdk${{ matrix.java }}-extra,enable=${{ matrix.extra == 'true' }}")
base_image_tags.forEach(tag => {
openjdk_tags.push(`type=raw,value=${tag},enable=${expr("matrix.extra == 'false' && matrix.java == '17'")}`)
openjdk_tags.push(`type=raw,value=${tag}-extra,enable=${expr("matrix.extra == 'true' && matrix.java == '17'")}`)
openjdk_tags.push(`type=raw,value=${tag}-jdk${expr("matrix.java")},enable=${expr("matrix.extra == 'false'")}`)
openjdk_tags.push(`type=raw,value=${tag}-jdk${expr("matrix.java")}-extra,enable=${expr("matrix.extra == 'true'")}`)
})
core.setOutput('openjdk_tags', openjdk_tags.join('\n'))
console.log('openjdk_tags:')
openjdk_tags.forEach(tag => console.log(`- ${tag}`))
env:
BASE_IMAGE_TAGS_WD: ${{ inputs.base_image_tags }}
BASE_IMAGE_TAGS_RD: ${{ github.event.client_payload.base_image_tags }}

outputs:
base_image_tag: ${{ steps.config.outputs.tag }}
base_image_tags: ${{ steps.config.outputs.tags }}
base_image_tag: ${{ steps.config.outputs.base_image_tag }}
base_image_tags: ${{ steps.config.outputs.base_image_tags }}
openjdk_tags: ${{ steps.config.outputs.openjdk_tags }}

extra:
name: Extra packages
needs: config
uses: ./.github/workflows/image_one.yml
secrets: inherit
with:
job_name: Extra packages
dockerfile_name: Dockerfile-extra
build_args: |-
BASE_IMAGE=mcdreforged/mcdreforged:${{ needs.config.outputs.base_image_tag }}
image_name: mcdreforged/mcdreforged-extra
image_tags: ${{ needs.config.outputs.base_image_tags }}

openjdk:
needs: extra
name: OpenJDK (jdk${{ matrix.java }}, ${{ matrix.distribution }}${{ matrix.extra == 'true' && ', extra' || '' }})
needs: [config, extra]
strategy:
matrix:
java: ['8', '11', '17', '21']
Expand All @@ -80,7 +88,6 @@ jobs:
uses: ./.github/workflows/image_one.yml
secrets: inherit
with:
job_name: OpenJDK (jdk${{ matrix.java }}, ${{ matrix.distribution }}${{ matrix.extra == 'true' && ', extra' || '' }})
dockerfile_name: Dockerfile-${{ matrix.distribution }}
build_args: |-
BASE_IMAGE=mcdreforged/${{ matrix.extra == 'true' && 'mcdreforged-extra' || 'mcdreforged' }}:${{ needs.config.outputs.base_image_tag }}
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/image_one.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: step.image_one
on:
workflow_call:
inputs:
job_name:
type: string
required: false
dockerfile_name:
type: string
required: true
Expand All @@ -28,7 +25,6 @@ on:

jobs:
image:
name: ${{ inputs.job_name }}
runs-on: ubuntu-latest
outputs:
imageid: ${{ steps.build.outputs.imageid }}
Expand Down

0 comments on commit 69a0117

Please sign in to comment.