Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to log diff between repost in "To upstream" badge #264

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/check-upstream.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch
import io.github.typesafegithub.workflows.dsl.workflow

val numberOfCommitsFileName = "number-of-commits.txt"
val logDiffBetweenRepos = "log-diff-between-repos.txt"
val badgeFileName = "commits-to-upstream-badge.svg"

workflow(
Expand All @@ -36,7 +37,11 @@ workflow(
git clone --branch master --single-branch https://bitbucket.org/snakeyaml/snakeyaml-engine.git
wget https://raw.githubusercontent.com/krzema12/snakeyaml-engine-kmp/${'$'}{{ github.ref }}/upstream-commit.txt
cd snakeyaml-engine
git log --oneline $(cat ../upstream-commit.txt)..master | wc -l > ../$numberOfCommitsFileName
UPSTREAM_COMMIT=$(cat ../upstream-commit.txt)
echo "See in BitBucket: https://bitbucket.org/snakeyaml/snakeyaml-engine/branches/compare/master..${'$'}UPSTREAM_COMMIT" > ../$logDiffBetweenRepos
echo "" >> ../$logDiffBetweenRepos
git log --oneline ${'$'}UPSTREAM_COMMIT..master >> ../$logDiffBetweenRepos
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: maybe introduce a shell variable with the command to avoid duplication?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but the new lines disappear when writing git's output stored in a variable to a text file. For sure there's a way to make it work, but I just think we can go with this minor duplication, unless you know from the top of your head how to fight this Bash peculiarity? 😁

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't unfortunately)

But I meant that you could extract the command itself into a variable and execute it like sh -c $command or eval $command (for bash)

cat ../$logDiffBetweenRepos | wc -l > ../$numberOfCommitsFileName
krzema12 marked this conversation as resolved.
Show resolved Hide resolved
""".trimIndent(),
)
run(
Expand All @@ -48,13 +53,18 @@ workflow(
command = "cat $badgeFileName",
)
run(
name = "Commit updated badge",
name = "Preview log diff",
command = "cat $logDiffBetweenRepos",
)
run(
name = "Commit updated badge and log diff",
command = """
git config --global user.email "<>"
git config --global user.name "GitHub Actions Bot"

git add $badgeFileName
git commit --allow-empty -m "Regenerate badge"
git add $logDiffBetweenRepos
git commit --allow-empty -m "Regenerate badge and log diff"
git push
""".trimIndent()
)
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/check-upstream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,27 @@ jobs:
git clone --branch master --single-branch https://bitbucket.org/snakeyaml/snakeyaml-engine.git
wget https://raw.githubusercontent.com/krzema12/snakeyaml-engine-kmp/${{ github.ref }}/upstream-commit.txt
cd snakeyaml-engine
git log --oneline $(cat ../upstream-commit.txt)..master | wc -l > ../number-of-commits.txt
UPSTREAM_COMMIT=$(cat ../upstream-commit.txt)
echo "See in BitBucket: https://bitbucket.org/snakeyaml/snakeyaml-engine/branches/compare/master..$UPSTREAM_COMMIT" > ../log-diff-between-repos.txt
echo "" >> ../log-diff-between-repos.txt
git log --oneline $UPSTREAM_COMMIT..master >> ../log-diff-between-repos.txt
cat ../log-diff-between-repos.txt | wc -l > ../number-of-commits.txt
- id: 'step-2'
name: 'Create an SVG with the number of commits'
run: 'wget -O commits-to-upstream-badge.svg https://img.shields.io/badge/To%20upstream-$(cat number-of-commits.txt)-blue'
- id: 'step-3'
name: 'Preview badge'
run: 'cat commits-to-upstream-badge.svg'
- id: 'step-4'
name: 'Commit updated badge'
name: 'Preview log diff'
run: 'cat log-diff-between-repos.txt'
- id: 'step-5'
name: 'Commit updated badge and log diff'
run: |-
git config --global user.email "<>"
git config --global user.name "GitHub Actions Bot"

git add commits-to-upstream-badge.svg
git commit --allow-empty -m "Regenerate badge"
git add log-diff-between-repos.txt
git commit --allow-empty -m "Regenerate badge and log diff"
git push
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Maven Central Version](https://maven-badges.herokuapp.com/maven-central/it.krzeminski/snakeyaml-engine-kmp/badge.svg)](https://maven-badges.herokuapp.com/maven-central/it.krzeminski/snakeyaml-engine-kmp)
![Commits to upstream](https://raw.githubusercontent.com/krzema12/snakeyaml-engine-kmp/refs/heads/commits-to-upstream-badge/commits-to-upstream-badge.svg)
[![Commits to upstream](https://raw.githubusercontent.com/krzema12/snakeyaml-engine-kmp/refs/heads/commits-to-upstream-badge/commits-to-upstream-badge.svg)](https://raw.githubusercontent.com/krzema12/snakeyaml-engine-kmp/refs/heads/commits-to-upstream-badge/log-diff-between-repos.txt)

# SnakeYAML Engine KMP

Expand Down
Loading