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

Add wesnoth-map-diff #6472

Merged
merged 3 commits into from Apr 27, 2022
Merged

Conversation

macabeus
Copy link
Contributor

@macabeus macabeus commented Jan 30, 2022

Solves #2323

This PR is a proposal to add a new command-line tool, wesnoth-map-diff.

It aims to be a CLI to produce an image comparing two tilemaps, used by a GitHub Action to comment on a PR automatically:
image

I'm writing it using JS because it's the language I'm most used to and be easy to develop this kind of tool.
To use it, you need to have Node.js. Then on your terminal:

> cd utils/wesnoth-map-diff
> npm i
> node src/index.js

@macabeus macabeus force-pushed the feat/add-wesnoth-map-diff branch 2 times, most recently from 00d1921 to b0fe192 Compare January 30, 2022 02:56
@Wedge009 Wedge009 added the Editor Map/scenario editor issues. label Jan 31, 2022
@Wedge009
Copy link
Member

Good on you for giving this a try. If you're not finished, you can always switch the PR to a draft.

@macabeus macabeus marked this pull request as draft January 31, 2022 09:47
@macabeus macabeus force-pushed the feat/add-wesnoth-map-diff branch 21 times, most recently from a0f8f61 to 10420e4 Compare March 6, 2022 21:18
for diff_image in ${{ steps.map-diff.outputs.DIFF_IMAGES }}
do
image_link=$(curl -X POST "https://api.imgur.com/3/upload" \
-F "image=@\"$diff_image\"" | jq ".data.link" -r)
Copy link
Contributor

Choose a reason for hiding this comment

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

How often will this upload images?

Copy link
Contributor Author

@macabeus macabeus Mar 7, 2022

Choose a reason for hiding this comment

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

It uploads an image whenever a PR (with a .map file) is opened or updated.

run: |
cd ./utils/wesnoth-map-diff

sudo apt-get install -y pngquant
Copy link
Contributor

Choose a reason for hiding this comment

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

There's already utils/woptipng.py

Copy link
Contributor Author

@macabeus macabeus Mar 12, 2022

Choose a reason for hiding this comment

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

I didn't notice this tool before.

But anyway, utils/woptipng.py isn't standalone.
It depends on a set of different packages (Pillow, advdef, imagemagick/convert, and optipng).

I think it's simpler just to install a single package (pngquant) and run it on this action.
pngquant works well for this kind of image as far as I checked.

.github/workflows/map-diff.yml Outdated Show resolved Hide resolved
.github/workflows/map-diff.yml Outdated Show resolved Hide resolved
.github/workflows/map-diff.yml Outdated Show resolved Hide resolved
@macabeus macabeus force-pushed the feat/add-wesnoth-map-diff branch 6 times, most recently from 5b0430b to aeb9f83 Compare March 13, 2022 15:22
@macabeus macabeus marked this pull request as ready for review March 13, 2022 15:25
@cooljeanius
Copy link
Contributor

This seems really cool; how do I use it in my repositories for UMC campaigns that I maintain?

@CelticMinstrel
Copy link
Member

CelticMinstrel commented Mar 13, 2022

The only thing I don't quite understand is… why upload the image to Imgur when GitHub itself supports image attachments on comments?

@cooljeanius It might be enough to just copy the workflow file to your repo (once this is merged).

@Elvish-Hunter
Copy link
Contributor

Quick question: since most of our users are on Windows, how can they run this tool on Windows systems? IMHO, a text file which explains how to do so would be appreciated.

@macabeus
Copy link
Contributor Author

macabeus commented Mar 13, 2022

@cooljeanius

This seems really cool; how do I use it in my repositories for UMC campaigns that I maintain?

There are two options:

  • run manually on your computer. You can follow the readme.
  • run using the github actions. It should work seamlessly just by copying and pasting.

@CelticMinstrel

why upload the image to Imgur when GitHub itself supports image attachments on comments?

Firstly, I tried to upload the image to GitHub. But it's harder since we need to have an authentication token.
Uploading to Imgur is easier, so I picked this solution.

@Elvish-Hunter

Quick question: since most of our users are on Windows, how can they run this tool on Windows systems? IMHO, a text file which explains how to do so would be appreciated.

There is the readme explaining it. But I can try to explain in more detail how to use it on Windows.

@Elvish-Hunter
Copy link
Contributor

There is the readme explaining it. But I can try to explain in more detail how to use it on Windows.

@macabeus Yes, I think that some detailed instructions for our Windows users would be really useful.

@macabeus
Copy link
Contributor Author

@Elvish-Hunter I just added more detail on the readme. Please, let me know if it's better now

## Get Maps
git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }}

map_paths=($(git diff --name-only HEAD ${{ github.event.pull_request.base.sha }} | grep ".map$"))
Copy link
Member

Choose a reason for hiding this comment

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

I cannot reproduce the issue with git diff --name-only HEAD ${{ github.event.pull_request.base.sha }} '*.map' but I think strictly it should be git diff --name-only HEAD ${{ github.event.pull_request.base.sha }} -- '*.map'

If grep is really necessary then it should be grep '\.map$' since a dot matches any character.

To not use word splitting and unintentionally pathname expansion it'd be better to use mapfile here:
mapfile -t map_paths < <(git diff --name-only HEAD ${{ github.event.pull_request.base.sha }} -- '*.map')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can reproduce the issue using my test repository:

> git clone git@github.com:macabeus/wesnoth.git
> cd wesnoth
> git checkout feat/add-wesnoth-map-diff-backup
> git diff --name-only HEAD 514b8bca9cf -- '*.map'

Copy link
Member

Choose a reason for hiding this comment

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

I cannot reproduce it there either. For me git works as documented.

$ git diff --name-only HEAD 514b8bca9cf -- '*.map'
data/test.map
data/test2.map

Anyway it's not that big a deal to keep the grep as well.

.github/workflows/map-diff.yml Outdated Show resolved Hide resolved
.github/workflows/map-diff.yml Outdated Show resolved Hide resolved
@Pentarctagon
Copy link
Member

If all comments have been addressed, it sounds like this can be merged?

@stevecotton
Copy link
Contributor

Do any of the reviewers know enough about the Node.js ecosystem to review this? I don't, @soliton- appears to be only reviewing the shell-script part, and the other commentators seem to be asking about how to run it rather than reviewing it.

@soliton-
Copy link
Member

Yeah, I didn't and don't intend to look at the js part.

@soliton-
Copy link
Member

Since it doesn't seem we'll get anyone to review the js part I would suggest to just merge this and see how it goes.

@Pentarctagon
Copy link
Member

I'll merge tomorrow then, barring anything else coming up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Editor Map/scenario editor issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants