forked from corretto/corretto-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github action to generate tags and diff
- Loading branch information
1 parent
1fac332
commit 70d12cf
Showing
3 changed files
with
141 additions
and
24 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 |
---|---|---|
@@ -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, | ||
}); | ||
} | ||
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 |
---|---|---|
@@ -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() |
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