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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/map-diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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: |
sudo apt-get install -y pngquant
comment_body=""

cd ./utils/wesnoth-map-diff

## Get maps changed
git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }}
mapfile -t map_paths < <(git diff --name-only HEAD ${{ github.event.pull_request.base.sha }} | grep '\.map$')

for map_path in "${map_paths[@]}"
do
## Get old map version
map_filename=${map_path##*/}
git show ${{ github.event.pull_request.base.sha }}:"$map_path" > "$map_filename"

## Run map diff
diff_image=${map_filename%.map}.png
node ./build/index.js "./$map_filename" "../../$map_path" "./$diff_image"

## Compress image
pngquant "$diff_image" -o "$diff_image" --force

## Write comment body
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.


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 }}
1 change: 1 addition & 0 deletions utils/wesnoth-map-diff/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
81 changes: 81 additions & 0 deletions utils/wesnoth-map-diff/.eslintrc.js
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' } },
],
},
}
4 changes: 4 additions & 0 deletions utils/wesnoth-map-diff/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.eslintcache

node_modules/
build/
39 changes: 39 additions & 0 deletions utils/wesnoth-map-diff/README.md
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
```
6 changes: 6 additions & 0 deletions utils/wesnoth-map-diff/babel.config.js
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',
],
}
3 changes: 3 additions & 0 deletions utils/wesnoth-map-diff/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
setupFilesAfterEnv: ['./setup-jest.js'],
}