Skip to content

Commit

Permalink
Add github action to generate tags and diff
Browse files Browse the repository at this point in the history
  • Loading branch information
cliveverghese committed Nov 23, 2021
1 parent 1fac332 commit 70d12cf
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 24 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/generate-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Verify repository and generate tags

on: [pull_request_target]

jobs:
verify-repository-content:
name: Verify repository content
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Generate repository content from version
run: |
bash bin/update-dockerfiles.sh
git diff -R | tee ${GITHUB_WORKSPACE}/pr.diff
- name: Generate tags for pr
run: |
python3 bin/tag-generator.py | tee ${GITHUB_WORKSPACE}/.tags
- name: Add Comment to PR
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
//Determine if new comment is required and generate comment text
commentText = 'Diff for ' + context.payload.pull_request.head.sha + ':\n\n'
needNewComment = true;
console.log('Reviewing existing comments...');
for await (const { data: comments } of github.paginate.iterator(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
}
)) {
for (const comment of comments) {
if (comment.user.login === 'github-actions[bot]') {
if (needNewComment && comment.body.includes(commentText)) {
needNewComment = false;
} else {
console.log('Deleting comment: ' + comment.id);
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
});
}
}
}
}
if (needNewComment) {
const fs = require('fs');
diff = fs.readFileSync(process.env.GITHUB_WORKSPACE + '/pr.diff').toString().trimEnd();
if (diff) {
commentText = commentText + "\n```\n" + diff + "\n```\n"
} else {
commentText = commentText + "The repository contains the expected content"
}
tags = fs.readFileSync(process.env.GITHUB_WORKSPACE + '/.tags').toString().trimEnd();
commentText = commentText + "<details>\n<summary>updated tags for [library/amazoncorretto](https://github.com/docker-library/official-images/blob/master/library/amazoncorretto)</summary>\n"
commentText = commentText + "\n```\n" + tags + "\n```\n</details>"
console.log('Creating new comment...');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: commentText,
});
}
42 changes: 42 additions & 0 deletions bin/tag-generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json

DEFAULT_ALPINE_VERSION = '3.12'
ALPINE_VERSIONS = ['3.12','3.13','3.14']

def generate_tags(key, version):
update = version.split('.')[1] if (key == '8') else version.split('.')[2]
expanded_version = f"{key}u{update}" if (key == '8') else f"{key}.0.{update}"

al2_tags = [f"{key}", f"{expanded_version}", f"{expanded_version}-al2", f"{key}-al2-full",f"{key}-al2-jdk"]
if key == '8':
al2_tags.append('latest')
print("Tags: " + ", ".join(al2_tags) + "")
print("Architectures: amd64, arm64v8")
print(f"Directory: {key}/jdk/al2\n")

for alpine_version in ALPINE_VERSIONS:
alpine_tags = [f"{key}-alpine{alpine_version}", f"{expanded_version}-alpine{alpine_version}", f"{key}-alpine{alpine_version}-full", f"{key}-alpine{alpine_version}-jdk"]
if alpine_version == DEFAULT_ALPINE_VERSION:
alpine_tags.extend([f"{key}-alpine", f"{expanded_version}-alpine", f"{key}-alpine-full", f"{key}-alpine-jdk"])
print("Tags: " + ", ".join(alpine_tags) + "")
print("Architectures: amd64")
print(f"Directory: {key}/jdk/alpine/{alpine_version}\n")
if key == '8':
alpine_jre_tags = [f"{key}-alpine{alpine_version}-jre", f"{expanded_version}-alpine{alpine_version}-jre"]
if alpine_version == DEFAULT_ALPINE_VERSION:
alpine_jre_tags.extend([f"{key}-alpine-jre", f"{expanded_version}-alpine-jre"])
print("Tags: " + ", ".join(alpine_jre_tags) + "")
print("Architectures: amd64")
print(f"Directory: {key}/jre/alpine/{alpine_version}\n")


def main():
with open('versions.json','r') as version_file:
versions = json.load(version_file)

with open('.tags', 'w') as tag_file:
for key in versions:
generate_tags(key, versions[key])

if __name__ == "__main__":
main()
45 changes: 21 additions & 24 deletions bin/update-dockerfiles.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
SED="sed -i"
sed --version 2>/dev/null || SED="sed -i.bkp"

usage() {
echo "usage: update-dockerfiles.sh [--help]"
Expand All @@ -10,16 +12,15 @@ update_musl_linux() {
CORRETTO_VERSION=$1
MAJOR_RELEASE=$2

sed -i "" "s/ARG version=.*/ARG version=${CORRETTO_VERSION}/g" ./${MAJOR_RELEASE}/jdk/alpine/Dockerfile
${SED} "s/ARG version=.*/ARG version=${CORRETTO_VERSION}/g" ./${MAJOR_RELEASE}/jdk/alpine/Dockerfile
if [ -f ./${MAJOR_RELEASE}/jre/alpine/Dockerfile ]; then
sed -i "" "s/ARG version=.*/ARG version=${CORRETTO_VERSION}/g" ./${MAJOR_RELEASE}/jre/alpine/Dockerfile
${SED} "s/ARG version=.*/ARG version=${CORRETTO_VERSION}/g" ./${MAJOR_RELEASE}/jre/alpine/Dockerfile
fi
jdk_version=$(echo ${CORRETTO_VERSION} | cut -d'.' -f1-3)
sed -i "" "s/${MAJOR_RELEASE}\.0\.[0-9]*-alpine/${jdk_version}-alpine/g" .tags

sed -i "" "s/${MAJOR_RELEASE}\.0\.[0-9]*-alpine/${jdk_version}-alpine/g" README.md
${SED} "s/${MAJOR_RELEASE}\.0\.[0-9]*-alpine/${jdk_version}-alpine/g" README.md
if [ -d "./${MAJOR_RELEASE}/slim" ]; then
sed -i "" "s/ARG version=.*/ARG version=${CORRETTO_VERSION}/g" ./${MAJOR_RELEASE}/slim/alpine/Dockerfile
${SED} "s/ARG version=.*/ARG version=${CORRETTO_VERSION}/g" ./${MAJOR_RELEASE}/slim/alpine/Dockerfile
fi
}

Expand All @@ -30,18 +31,15 @@ update_generic_linux() {
jdk_version=$(echo ${CORRETTO_VERSION} | cut -d'.' -f1-3)
jdk_build=$(echo ${CORRETTO_VERSION} | cut -d'.' -f4)
corretto_version=$(echo ${CORRETTO_VERSION} | cut -d'.' -f5)
sed -i "" "s/ARG version=.*/ARG version=${jdk_version}.${jdk_build}-${corretto_version}/g" ./${MAJOR_RELEASE}/jdk/al2/Dockerfile
sed -i "" "s/ARG version=.*/ARG version=${jdk_version}.${jdk_build}-${corretto_version}/g" ./${MAJOR_RELEASE}/jdk/debian/Dockerfile
sed -i "" "s/${MAJOR_RELEASE}\.0\.[0-9]*,/${jdk_version},/g" .tags
sed -i "" "s/${MAJOR_RELEASE}\.0\.[0-9]*-al2/${jdk_version}-al2/g" .tags
${SED} "s/ARG version=.*/ARG version=${jdk_version}.${jdk_build}-${corretto_version}/g" ./${MAJOR_RELEASE}/jdk/al2/Dockerfile
${SED} "s/ARG version=.*/ARG version=${jdk_version}.${jdk_build}-${corretto_version}/g" ./${MAJOR_RELEASE}/jdk/debian/Dockerfile

sed -i "" "s/${MAJOR_RELEASE}\.0\.[0-9]*,/${jdk_version},/g" README.md
sed -i "" "s/${MAJOR_RELEASE}\.0\.[0-9]*-al2/${jdk_version}-al2/g" README.md
${SED} "s/${MAJOR_RELEASE}\.0\.[0-9]*,/${jdk_version},/g" README.md
${SED} "s/${MAJOR_RELEASE}\.0\.[0-9]*-al2/${jdk_version}-al2/g" README.md
if [ -d "./${MAJOR_RELEASE}/slim" ]; then
sed -i "" "s/ARG version=.*/ARG version=${jdk_version}.${jdk_build}-${corretto_version}/g" ./${MAJOR_RELEASE}/slim/al2/Dockerfile
sed -i "" "s/ARG version=.*/ARG version=${jdk_version}.${jdk_build}-${corretto_version}/g" ./${MAJOR_RELEASE}/slim/debian/Dockerfile
sed -i "" "s/${MAJOR_RELEASE}\.0\.[0-9]*-slim,/${jdk_version},/g" .tags
sed -i "" "s/${MAJOR_RELEASE}\.0\.[0-9]*-slim,/${jdk_version},/g" README.md
${SED} "s/ARG version=.*/ARG version=${jdk_version}.${jdk_build}-${corretto_version}/g" ./${MAJOR_RELEASE}/slim/al2/Dockerfile
${SED} "s/ARG version=.*/ARG version=${jdk_version}.${jdk_build}-${corretto_version}/g" ./${MAJOR_RELEASE}/slim/debian/Dockerfile
${SED} "s/${MAJOR_RELEASE}\.0\.[0-9]*-slim,/${jdk_version},/g" README.md
fi

}
Expand All @@ -62,29 +60,28 @@ done

CORRETTO_8_GENERIC_LINUX=$(cat versions.json | jq -r '.["8"]' )
CORRETTO_11_GENERIC_LINUX=$(cat versions.json | jq -r '.["11"]' )
CORRETTO_16_GENERIC_LINUX=$(cat versions.json | jq -r '.["16"]' )
CORRETTO_17_GENERIC_LINUX=$(cat versions.json | jq -r '.["17"]' )


if [ ! -z "${CORRETTO_11_GENERIC_LINUX}" ]; then
update_generic_linux ${CORRETTO_11_GENERIC_LINUX} 11
fi

if [ ! -z "${CORRETTO_16_GENERIC_LINUX}" ]; then
update_generic_linux ${CORRETTO_16_GENERIC_LINUX} 16
if [ ! -z "${CORRETTO_17_GENERIC_LINUX}" ]; then
update_generic_linux ${CORRETTO_17_GENERIC_LINUX} 17
fi

if [ ! -z "${CORRETTO_8_GENERIC_LINUX}" ]; then
jdk_version=$(echo ${CORRETTO_8_GENERIC_LINUX} | cut -d'.' -f2)
jdk_build=$(echo ${CORRETTO_8_GENERIC_LINUX} | cut -d'.' -f3)
corretto_version=$(echo ${CORRETTO_8_GENERIC_LINUX} | cut -d'.' -f4)
sed -i "" "s/ARG version=.*/ARG version=1.8.0_${jdk_version}.b${jdk_build}-${corretto_version}/g" ./8/jdk/al2/Dockerfile
sed -i "" "s/ARG version=.*/ARG version=8.${jdk_version}.${jdk_build}-${corretto_version}/g" ./8/jdk/debian/Dockerfile
sed -i "" "s/8u[0-9]*,/8u${jdk_version},/g" .tags
sed -i "" "s/8u[0-9]*-al2/8u${jdk_version}-al2/g" .tags
${SED} "s/ARG version=.*/ARG version=1.8.0_${jdk_version}.b${jdk_build}-${corretto_version}/g" ./8/jdk/al2/Dockerfile
${SED} "s/ARG version=.*/ARG version=8.${jdk_version}.${jdk_build}-${corretto_version}/g" ./8/jdk/debian/Dockerfile

sed -i "" "s/8u[0-9]*,/8u${jdk_version},/g" README.md
sed -i "" "s/8u[0-9]*-al2/8u${jdk_version}-al2/g" README.md
${SED} "s/8u[0-9]*,/8u${jdk_version},/g" README.md
${SED} "s/8u[0-9]*-al2/8u${jdk_version}-al2/g" README.md
fi

find . -name "*.bkp" | xargs rm -rf

python3 bin/apply-template.py

0 comments on commit 70d12cf

Please sign in to comment.