-
-
Notifications
You must be signed in to change notification settings - Fork 991
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
Add wesnoth-map-diff
#6472
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Map Diff | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**.map' | ||
|
||
jobs: | ||
comment-map-diff: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v3.0.0 | ||
- uses: actions/setup-node@v3.0.0 | ||
with: | ||
node-version: '16' | ||
- name: Package install | ||
run: | | ||
cd ./utils/wesnoth-map-diff | ||
npm install | ||
- name: Package build | ||
run: | | ||
cd ./utils/wesnoth-map-diff | ||
npm run build:prod | ||
- name: Get maps diff | ||
id: get-maps-diff | ||
run: | | ||
cd ./utils/wesnoth-map-diff | ||
|
||
## 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$")) | ||
|
||
for map_path in "${map_paths[@]}" | ||
do | ||
map_filename=$(basename "$map_path") | ||
git show ${{ github.event.pull_request.base.sha }}:$map_path > $map_filename | ||
macabeus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
done | ||
|
||
## Run map diff | ||
diff_images=() | ||
|
||
for map_path in "${map_paths[@]}" | ||
do | ||
map_filename=$(basename "$map_path") | ||
output_filename=$(echo "$map_filename" | perl -pe 's/map$/png/') | ||
macabeus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
node ./build/index.js "./$map_filename" "../../$map_path" "./$output_filename" | ||
|
||
diff_images+=("$output_filename") | ||
done | ||
|
||
## Compress images | ||
sudo apt-get install -y pngquant | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's already utils/woptipng.py There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't notice this tool before. But anyway, I think it's simpler just to install a single package ( |
||
|
||
for diff_image in "${diff_images[@]}" | ||
do | ||
pngquant "$diff_image" -o "$diff_image" --force | ||
done | ||
|
||
## Write comment body | ||
comment_body="" | ||
|
||
for i in "${!diff_images[@]}" | ||
do | ||
map_path=${map_paths[$i]} | ||
diff_image=${diff_images[$i]} | ||
|
||
image_link=$(curl -X POST "https://api.imgur.com/3/upload" \ | ||
-F "image=@\"$diff_image\"" | jq ".data.link" -r) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How often will this upload images? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It uploads an image whenever a PR (with a |
||
|
||
comment_body="$comment_body<h3>$map_path</h3><img src=\"$image_link\" /><br />" | ||
done | ||
|
||
echo "::set-output name=COMMENT_BODY::$comment_body" | ||
- name: Add comment | ||
uses: peter-evans/create-or-update-comment@v1.4.5 | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
edit-mode: replace | ||
body: | | ||
${{ steps.get-maps-diff.outputs.COMMENT_BODY }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
plugins: [ | ||
'@typescript-eslint', | ||
], | ||
overrides: [ | ||
{ | ||
files: ['**/*.ts'], | ||
}, | ||
], | ||
extends: [ | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
rules: { | ||
'@typescript-eslint/member-delimiter-style': ['error', { | ||
multiline: { | ||
delimiter: 'comma', | ||
requireLast: true, | ||
}, | ||
singleline: { | ||
delimiter: 'comma', | ||
requireLast: false, | ||
}, | ||
}], | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
'@typescript-eslint/no-empty-interface': [ | ||
'error', | ||
{ | ||
allowSingleExtends: true, | ||
}, | ||
], | ||
'@typescript-eslint/no-var-requires': 'off', | ||
'arrow-parens': 'off', | ||
'comma-dangle': [ | ||
'error', | ||
{ | ||
arrays: 'always-multiline', | ||
exports: 'always-multiline', | ||
functions: 'never', | ||
imports: 'always-multiline', | ||
objects: 'always-multiline', | ||
}, | ||
], | ||
'function-paren-newline': ['error', 'consistent'], | ||
'quote-props': ['error', 'as-needed'], | ||
'max-len': [ | ||
'error', | ||
{ | ||
code: 120, | ||
ignoreComments: true, | ||
ignoreRegExpLiterals: true, | ||
ignoreStrings: true, | ||
ignoreTemplateLiterals: true, | ||
ignoreTrailingComments: true, | ||
ignoreUrls: true, | ||
tabWidth: 2, | ||
}, | ||
], | ||
'multiline-ternary': ['error', 'always-multiline'], | ||
'no-unused-expressions': ['error', { allowTernary: true }], | ||
'no-multiple-empty-lines': [ | ||
'error', | ||
{ | ||
max: 1, | ||
maxEOF: 1, | ||
}, | ||
], | ||
'implicit-arrow-linebreak': 'off', | ||
'import/extensions': 'off', | ||
'import/no-unresolved': 'off', | ||
semi: ['error', 'never'], | ||
'space-before-function-paren': ['error', 'always'], | ||
'object-curly-spacing': ['error', 'always'], | ||
'operator-linebreak': [ | ||
'error', | ||
'before', | ||
{ overrides: { '=': 'after', ':': 'before', '?': 'before' } }, | ||
], | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.eslintcache | ||
|
||
node_modules/ | ||
build/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# wesnoth-map-diff | ||
|
||
> 🗺 Print the diff between two maps | ||
|
||
## Setup | ||
|
||
1 - Make sure you have Node on your system. If you don't have it, install it. If you are using macOS or Linux, you can install Node using [nvm](https://github.com/nvm-sh/nvm). On Windows, use [nvm-windows](https://github.com/coreybutler/nvm-windows). | ||
|
||
2 - Open the terminal on `utils/wesnoth-map-diff` folder and run the following command to install the project dependencies: | ||
|
||
``` | ||
npm i | ||
``` | ||
|
||
3 - Then, run the following command to build it: | ||
|
||
``` | ||
npm run build:dev | ||
``` | ||
|
||
4 - Finally, run it using `node ./build/index.js [path for the old map] [path for the new map] [output filename]`. For instance: | ||
|
||
``` | ||
node ./build/index.js old.map new.map output.png | ||
``` | ||
|
||
## Contributing | ||
|
||
Run tests: | ||
|
||
``` | ||
npm run test | ||
``` | ||
|
||
Run lint: | ||
|
||
``` | ||
npm run lint | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', { targets: { node: 'current' } }], | ||
'@babel/preset-typescript', | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
setupFilesAfterEnv: ['./setup-jest.js'], | ||
} |
There was a problem hiding this comment.
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 begit 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')
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
Anyway it's not that big a deal to keep the grep as well.