mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-04-20 09:01:23 +00:00
Make image and tag in lowercase if found in uppercase
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
5b84b38144
commit
32dc2ef031
4 changed files with 95 additions and 14 deletions
66
.github/workflows/check-lowercase.yaml
vendored
Normal file
66
.github/workflows/check-lowercase.yaml
vendored
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
# This workflow will perform a test whenever there
|
||||||
|
# is some change in code done to ensure that the changes
|
||||||
|
# are not buggy and we are getting the desired output.
|
||||||
|
name: Check Case Normalization
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *' # every day at midnight
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE_NAME: ImageCaseTest
|
||||||
|
IMAGE_TAGS: v1 TagCaseTest
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build image using Buildah
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
install_latest: [ true, false ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
# Checkout buildah action github repository
|
||||||
|
- name: Checkout Buildah action
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "buildah-build"
|
||||||
|
|
||||||
|
- name: Install latest buildah
|
||||||
|
if: matrix.install_latest
|
||||||
|
run: |
|
||||||
|
bash buildah-build/.github/install_latest_buildah.sh
|
||||||
|
|
||||||
|
- name: Create Dockerfile
|
||||||
|
run: |
|
||||||
|
cat > Containerfile<<EOF
|
||||||
|
FROM busybox
|
||||||
|
RUN echo "hello world"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Build image using Buildah action
|
||||||
|
- name: Build Image
|
||||||
|
id: build_image
|
||||||
|
uses: ./buildah-build/
|
||||||
|
with:
|
||||||
|
image: ${{ env.IMAGE_NAME }}
|
||||||
|
layers: false
|
||||||
|
tags: ${{ env.IMAGE_TAGS }}
|
||||||
|
containerfiles: |
|
||||||
|
./Containerfile
|
||||||
|
extra-args: |
|
||||||
|
--pull
|
||||||
|
|
||||||
|
- name: Echo Outputs
|
||||||
|
run: |
|
||||||
|
echo "Image: ${{ steps.build_image.outputs.image }}"
|
||||||
|
echo "Tags: ${{ steps.build_image.outputs.tags }}"
|
||||||
|
echo "Tagged Image: ${{ steps.build_image.outputs.image-with-tag }}"
|
||||||
|
|
||||||
|
# Check if image is build
|
||||||
|
- name: Check images created
|
||||||
|
run: buildah images
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
39
src/index.ts
39
src/index.ts
|
@ -37,6 +37,20 @@ export async function run(): Promise<void> {
|
||||||
const labels = core.getInput(Inputs.LABELS);
|
const labels = core.getInput(Inputs.LABELS);
|
||||||
const labelsList: string[] = labels ? splitByNewline(labels) : [];
|
const labelsList: string[] = labels ? splitByNewline(labels) : [];
|
||||||
|
|
||||||
|
const normalizedTagsList: string[] = [];
|
||||||
|
let isNormalized = false;
|
||||||
|
for (const tag of tagsList) {
|
||||||
|
normalizedTagsList.push(tag.toLowerCase());
|
||||||
|
if (tag.toLowerCase() !== tag) {
|
||||||
|
isNormalized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const normalizedImage = image.toLowerCase();
|
||||||
|
if (isNormalized || image !== normalizedImage) {
|
||||||
|
core.warning(`Reference to image and/or tag must be lowercase.`
|
||||||
|
+ ` Reference has been converted to be compliant with standard.`);
|
||||||
|
}
|
||||||
|
|
||||||
// info message if user doesn't provides any tag
|
// info message if user doesn't provides any tag
|
||||||
if (tagsList.length === 0) {
|
if (tagsList.length === 0) {
|
||||||
core.info(`Input "${Inputs.TAGS}" is not provided, using default tag "${DEFAULT_TAG}"`);
|
core.info(`Input "${Inputs.TAGS}" is not provided, using default tag "${DEFAULT_TAG}"`);
|
||||||
|
@ -44,15 +58,15 @@ export async function run(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if all tags provided are in `image:tag` format
|
// check if all tags provided are in `image:tag` format
|
||||||
const isFullImageNameTag = isFullImageName(tagsList[0]);
|
const isFullImageNameTag = isFullImageName(normalizedTagsList[0]);
|
||||||
if (tagsList.some((tag) => isFullImageName(tag) !== isFullImageNameTag)) {
|
if (normalizedTagsList.some((tag) => isFullImageName(tag) !== isFullImageNameTag)) {
|
||||||
throw new Error(`Input "${Inputs.TAGS}" cannot have a mix of full name and non full name tags. Refer to https://github.com/redhat-actions/buildah-build#image-tag-inputs`);
|
throw new Error(`Input "${Inputs.TAGS}" cannot have a mix of full name and non full name tags. Refer to https://github.com/redhat-actions/buildah-build#image-tag-inputs`);
|
||||||
}
|
}
|
||||||
if (!isFullImageNameTag && !image) {
|
if (!isFullImageNameTag && !normalizedImage) {
|
||||||
throw new Error(`Input "${Inputs.IMAGE}" must be provided when not using full image name tags. Refer to https://github.com/redhat-actions/buildah-build#image-tag-inputs`);
|
throw new Error(`Input "${Inputs.IMAGE}" must be provided when not using full image name tags. Refer to https://github.com/redhat-actions/buildah-build#image-tag-inputs`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newImage = getFullImageName(image, tagsList[0]);
|
const newImage = getFullImageName(normalizedImage, normalizedTagsList[0]);
|
||||||
const useOCI = core.getInput(Inputs.OCI) === "true";
|
const useOCI = core.getInput(Inputs.OCI) === "true";
|
||||||
|
|
||||||
const archs = getArch();
|
const archs = getArch();
|
||||||
|
@ -75,10 +89,11 @@ export async function run(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((archs.length > 1) || (platforms.length > 1)) {
|
if ((archs.length > 1) || (platforms.length > 1)) {
|
||||||
core.info(`Creating manifest with tag${tagsList.length !== 1 ? "s" : ""} "${tagsList.join(", ")}"`);
|
core.info(`Creating manifest with tag${normalizedTagsList.length !== 1 ? "s" : ""} `
|
||||||
|
+ `"${normalizedTagsList.join(", ")}"`);
|
||||||
const builtManifest = [];
|
const builtManifest = [];
|
||||||
for (const tag of tagsList) {
|
for (const tag of normalizedTagsList) {
|
||||||
const manifestName = getFullImageName(image, tag);
|
const manifestName = getFullImageName(normalizedImage, tag);
|
||||||
await cli.manifestCreate(manifestName);
|
await cli.manifestCreate(manifestName);
|
||||||
builtManifest.push(manifestName);
|
builtManifest.push(manifestName);
|
||||||
|
|
||||||
|
@ -96,14 +111,14 @@ export async function run(): Promise<void> {
|
||||||
core.info(`✅ Successfully built image${builtImage.length !== 1 ? "s" : ""} "${builtImage.join(", ")}" `
|
core.info(`✅ Successfully built image${builtImage.length !== 1 ? "s" : ""} "${builtImage.join(", ")}" `
|
||||||
+ `and manifest${builtManifest.length !== 1 ? "s" : ""} "${builtManifest.join(", ")}"`);
|
+ `and manifest${builtManifest.length !== 1 ? "s" : ""} "${builtManifest.join(", ")}"`);
|
||||||
}
|
}
|
||||||
else if (tagsList.length > 1) {
|
else if (normalizedTagsList.length > 1) {
|
||||||
await cli.tag(image, tagsList);
|
await cli.tag(normalizedImage, normalizedTagsList);
|
||||||
}
|
}
|
||||||
else if (tagsList.length === 1) {
|
else if (normalizedTagsList.length === 1) {
|
||||||
core.info(`✅ Successfully built image "${getFullImageName(image, tagsList[0])}"`);
|
core.info(`✅ Successfully built image "${getFullImageName(normalizedImage, normalizedTagsList[0])}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput(Outputs.IMAGE, image);
|
core.setOutput(Outputs.IMAGE, normalizedImage);
|
||||||
core.setOutput(Outputs.TAGS, tags);
|
core.setOutput(Outputs.TAGS, tags);
|
||||||
core.setOutput(Outputs.IMAGE_WITH_TAG, newImage);
|
core.setOutput(Outputs.IMAGE_WITH_TAG, newImage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue