-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only build and publish new ROCK version if rockfile.yaml changed (#16)
- Loading branch information
Showing
1 changed file
with
71 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,9 @@ on: | |
rock-metas: | ||
description: List of maps featuring the built {name, version, path, arch, image} | ||
value: ${{ jobs.get-rocks.outputs.rock-metas }} | ||
changed-rock-metas: | ||
description: List of maps featuring the built that has changed {name, version, path, arch, image} | ||
value: ${{ jobs.get-rocks.outputs.changed-rock-metas }} | ||
|
||
jobs: | ||
get-rocks: | ||
|
@@ -78,6 +81,7 @@ jobs: | |
rock-paths: ${{ steps.gen-rock-paths-and-images.outputs.rock-paths }} | ||
images: "${{ steps.gen-rock-paths-and-images.outputs.images }}" | ||
rock-metas: ${{ steps.gen-rock-paths-and-images.outputs.rock-metas }} | ||
changed-rock-metas: ${{ steps.gen-rock-paths-and-images.outputs.changed-rock-metas }} | ||
steps: | ||
- name: Validate inputs | ||
run: | | ||
|
@@ -86,6 +90,13 @@ jobs: | |
exit 1 | ||
fi | ||
- uses: actions/[email protected] | ||
- uses: dorny/paths-filter@v3 | ||
id: changes | ||
with: | ||
list-files: 'json' | ||
filters: | | ||
rocks: | ||
- '**/rockcraft.yaml' | ||
- name: Generate rock paths and images | ||
id: gen-rock-paths-and-images | ||
uses: actions/[email protected] | ||
|
@@ -96,69 +107,85 @@ jobs: | |
const workingDir = inputs['working-directory'] | ||
const multiarch = inputs['multiarch-awareness'] | ||
const rockcraftGlobber = await glob.create( | ||
path.join(workingDir, '**/rockcraft.yaml') | ||
path.join(workingDir, '**/rockcraft.yaml') | ||
) | ||
const rockPaths = [] | ||
const images = [] | ||
const rockMetas = [] | ||
const changedMetas = [] | ||
const defaultArch = 'amd64' | ||
const changes = ${{ toJSON(steps.changes) }} | ||
const changesPaths = JSON.parse(changes['outputs']['rocks_files']) | ||
const platformLabels = JSON.parse(inputs['platform-labels']) | ||
const rockcraftRevisions = JSON.parse(inputs['rockcraft-revisions']) | ||
core.info(`Multiarch Awareness is ${multiarch ? "on" : "off" }`) | ||
const isPullRequest = ${{ github.event_name == 'pull_request' }} | ||
core.info(`Multiarch Awareness is ${multiarch ? "on" : "off"}`) | ||
for (const rockcraftFile of await rockcraftGlobber.glob()) { | ||
const rockPath = path.relative('.', path.dirname(rockcraftFile)) || "./" | ||
core.info(`found rockcraft.yaml in ${rockPath}`) | ||
const fileHash = await glob.hashFiles(path.join(rockPath, '**')) | ||
const [rockName, rockVersion] = ( | ||
await exec.getExecOutput('yq', ['.name,.version', rockcraftFile]) | ||
).stdout.trim().split("\n") | ||
const platforms = ( | ||
await exec.getExecOutput('yq', ['.platforms | keys', '-o=json', rockcraftFile]) | ||
).stdout.trim() | ||
if (multiarch && platforms) { | ||
const arches = JSON.parse(platforms) | ||
for (arch of arches) { | ||
const image = `${{ inputs.registry }}/${{ inputs.owner }}/${rockName}:${fileHash}-${arch}` | ||
core.info(`generate multi-arch image name: ${image}`) | ||
images.push(image) | ||
rockMetas.push({ | ||
name: rockName, | ||
version: rockVersion, | ||
path: rockPath, | ||
arch: arch, | ||
image: image, | ||
"rockcraft-revision": rockcraftRevisions[arch] || '', | ||
"runs-on-labels": platformLabels[arch] || [inputs["runs-on"]] | ||
}) | ||
const rockPath = path.relative('.', path.dirname(rockcraftFile)) || "./" | ||
core.info(`found rockcraft.yaml in ${rockPath}`) | ||
const fileHash = await glob.hashFiles(path.join(rockPath, '**')) | ||
const [rockName, rockVersion] = ( | ||
await exec.getExecOutput('yq', ['.name,.version', rockcraftFile]) | ||
).stdout.trim().split("\n") | ||
const platforms = ( | ||
await exec.getExecOutput('yq', ['.platforms | keys', '-o=json', rockcraftFile]) | ||
).stdout.trim() | ||
if (multiarch && platforms) { | ||
const arches = JSON.parse(platforms) | ||
for (arch of arches) { | ||
const image = `${{inputs.registry}}/${{inputs.owner}}/${rockName}:${fileHash}-${arch}` | ||
core.info(`generate multi-arch image name: ${image}`) | ||
images.push(image) | ||
let meta = { | ||
name: rockName, | ||
version: rockVersion, | ||
path: rockPath, | ||
arch: arch, | ||
image: image, | ||
"rockcraft-revision": rockcraftRevisions[arch] || '', | ||
"runs-on-labels": platformLabels[arch] || [inputs["runs-on"]] | ||
} | ||
rockMetas.push(meta) | ||
if (isPullRequest && changesPaths.includes(`${rockPath}/rockcraft.yaml`)) { | ||
changedMetas.push(meta) | ||
} else if (!isPullRequest) { | ||
changedMetas.push(meta) | ||
} | ||
} | ||
} else { | ||
const image = `${{inputs.registry}}/${{inputs.owner}}/${rockName}:${fileHash}` | ||
core.info(`generate image name: ${image}`) | ||
images.push(image) | ||
let meta = { | ||
name: rockName, | ||
version: rockVersion, | ||
path: rockPath, | ||
arch: defaultArch, | ||
image: image, | ||
"rockcraft-revision": rockcraftRevisions[defaultArch] || '', | ||
"runs-on-labels": platformLabels[defaultArch] || [inputs["runs-on"]] | ||
}; | ||
rockMetas.push(meta) | ||
if (isPullRequest && changesPaths.includes(`${rockPath}/rockcraft.yaml`)) { | ||
changedMetas.push(meta) | ||
} else if (!isPullRequest) { | ||
changedMetas.push(meta) | ||
} | ||
} | ||
} else { | ||
const image = `${{ inputs.registry }}/${{ inputs.owner }}/${rockName}:${fileHash}` | ||
core.info(`generate image name: ${image}`) | ||
images.push(image) | ||
rockMetas.push({ | ||
name: rockName, | ||
version: rockVersion, | ||
path: rockPath, | ||
arch: defaultArch, | ||
image: image, | ||
"rockcraft-revision": rockcraftRevisions[defaultArch] || '', | ||
"runs-on-labels": platformLabels[defaultArch] || [inputs["runs-on"]] | ||
}) | ||
} | ||
rockPaths.push(rockPath) | ||
rockPaths.push(rockPath) | ||
} | ||
core.setOutput('rock-metas', JSON.stringify(rockMetas)) | ||
core.setOutput('changed-rock-metas', JSON.stringify(changedMetas)) | ||
core.setOutput('rock-paths', JSON.stringify(rockPaths)) | ||
core.setOutput('images', JSON.stringify(images)) | ||
build-rocks: | ||
name: Build rock | ||
needs: [get-rocks] | ||
if: ${{ needs.get-rocks.outputs.rock-metas != '[]' }} | ||
if: ${{ needs.get-rocks.outputs.changed-rock-metas != '[]' }} | ||
strategy: | ||
matrix: | ||
rock: ${{ fromJSON(needs.get-rocks.outputs.rock-metas) }} | ||
rock: ${{ fromJSON(needs.get-rocks.outputs.changed-rock-metas) }} | ||
fail-fast: false | ||
runs-on: ${{ matrix.rock.runs-on-labels }} | ||
permissions: | ||
|