Skip to content

Commit 1e7381d

Browse files
authored
DEV: Add CI setup and fix linting issues (#11)
1 parent 3d341a4 commit 1e7381d

File tree

11 files changed

+2195
-27
lines changed

11 files changed

+2195
-27
lines changed

.eslintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "eslint-config-discourse",
3+
"ignorePatterns": ["javascripts/vendor/*"],
4+
"globals": {
5+
"settings": "readonly",
6+
"themePrefix": "readonly"
7+
}
8+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Linting
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
concurrency:
10+
group: plugin-linting-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: 16
24+
cache: yarn
25+
26+
- name: Yarn install
27+
run: yarn install
28+
29+
- name: ESLint
30+
if: ${{ always() }}
31+
run: yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern {test,javascripts}
32+
33+
- name: Prettier
34+
if: ${{ always() }}
35+
shell: bash
36+
run: |
37+
yarn prettier -v
38+
files=$(find javascripts desktop mobile common scss -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" \) 2> /dev/null) || true
39+
if [ -n "$files" ]; then
40+
yarn prettier --list-different $files
41+
fi
42+
if [ 0 -lt $(find test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
43+
yarn prettier --list-different "test/**/*.{js,es6}"
44+
fi
45+
46+
- name: Ember template lint
47+
if: ${{ always() }}
48+
run: yarn ember-template-lint --no-error-on-unmatched-pattern javascripts
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
concurrency:
10+
group: plugin-tests-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
check:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
tests_exist: ${{ steps.check_tests.outputs.tests_exist }}
18+
19+
steps:
20+
- name: Install component
21+
uses: actions/checkout@v3
22+
with:
23+
path: tmp/component
24+
fetch-depth: 1
25+
26+
- name: Check QUnit existence
27+
id: check_tests
28+
shell: bash
29+
run: |
30+
if [ 0 -lt $(find tmp/component/test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
31+
echo "::set-output name=tests_exist::true"
32+
fi
33+
34+
test:
35+
needs: check
36+
if: ${{ needs.check.outputs.tests_exist }}
37+
runs-on: ubuntu-latest
38+
container: discourse/discourse_test:slim-browsers
39+
timeout-minutes: 15
40+
41+
env:
42+
DISCOURSE_HOSTNAME: www.example.com
43+
RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072
44+
RAILS_ENV: development
45+
PGUSER: discourse
46+
PGPASSWORD: discourse
47+
48+
steps:
49+
- uses: actions/checkout@v3
50+
with:
51+
repository: discourse/discourse
52+
fetch-depth: 1
53+
54+
- name: Install component
55+
uses: actions/checkout@v3
56+
with:
57+
path: tmp/component
58+
fetch-depth: 1
59+
60+
- name: Setup Git
61+
run: |
62+
git config --global user.email "[email protected]"
63+
git config --global user.name "Discourse CI"
64+
65+
- name: Start redis
66+
run: |
67+
redis-server /etc/redis/redis.conf &
68+
69+
- name: Start Postgres
70+
run: |
71+
chown -R postgres /var/run/postgresql
72+
sudo -E -u postgres script/start_test_db.rb
73+
sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';"
74+
75+
- name: Bundler cache
76+
uses: actions/cache@v3
77+
with:
78+
path: vendor/bundle
79+
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
80+
restore-keys: |
81+
${{ runner.os }}-gem-
82+
83+
- name: Setup gems
84+
run: |
85+
gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' Gemfile.lock)
86+
bundle config --local path vendor/bundle
87+
bundle config --local deployment true
88+
bundle config --local without development
89+
bundle install --jobs 4
90+
bundle clean
91+
92+
- name: Lint English locale
93+
run: bundle exec ruby script/i18n_lint.rb "tmp/component/locales/en.yml"
94+
95+
- name: Get yarn cache directory
96+
id: yarn-cache-dir
97+
run: echo "::set-output name=dir::$(yarn cache dir)"
98+
99+
- name: Yarn cache
100+
uses: actions/cache@v3
101+
id: yarn-cache
102+
with:
103+
path: ${{ steps.yarn-cache-dir.outputs.dir }}
104+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
105+
restore-keys: |
106+
${{ runner.os }}-yarn-
107+
108+
- name: Yarn install
109+
run: yarn install
110+
111+
- name: Fetch app state cache
112+
uses: actions/cache@v3
113+
id: app-cache
114+
with:
115+
path: tmp/app-cache
116+
key: >-
117+
${{ hashFiles('.github/workflows/tests.yml') }}-
118+
${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }}-
119+
120+
- name: Restore database from cache
121+
if: steps.app-cache.outputs.cache-hit == 'true'
122+
run: psql -f tmp/app-cache/cache.sql postgres
123+
124+
- name: Restore uploads from cache
125+
if: steps.app-cache.outputs.cache-hit == 'true'
126+
run: rm -rf public/uploads && cp -r tmp/app-cache/uploads public/uploads
127+
128+
- name: Create and migrate database
129+
if: steps.app-cache.outputs.cache-hit != 'true'
130+
run: |
131+
bin/rake db:create
132+
bin/rake db:migrate
133+
134+
- name: Dump database for cache
135+
if: steps.app-cache.outputs.cache-hit != 'true'
136+
run: mkdir -p tmp/app-cache && pg_dumpall > tmp/app-cache/cache.sql
137+
138+
- name: Dump uploads for cache
139+
if: steps.app-cache.outputs.cache-hit != 'true'
140+
run: rm -rf tmp/app-cache/uploads && cp -r public/uploads tmp/app-cache/uploads
141+
142+
- name: Component QUnit
143+
run: |
144+
THEME_NAME=$(ruby -e 'require "json"; puts JSON.parse(File.read("tmp/component/about.json"))["name"]')
145+
bundle exec rake themes:install -- "--{\"$THEME_NAME\": \"tmp/component\"}"
146+
UNICORN_TIMEOUT=120 bundle exec rake "themes:qunit[name,$THEME_NAME]"
147+
timeout-minutes: 10

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.discourse-site

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.template-lintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
plugins: ["ember-template-lint-plugin-discourse"],
3+
extends: "discourse:recommended",
4+
};

about.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "Header submenus",
3-
"about_url": "https://meta.discourse.org/t/",
4-
"license_url": "https://github.com/discourse/discourse-header-submenus/blob/main/LICENSE",
5-
"component": true
3+
"component": true,
4+
"license_url": "https://github.com/discourse/discourse-header-submenus/blob/main/LICENSE"
65
}
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
1-
<div id='top-menu' class='top-menu'>
2-
<div class='menu-content wrap'>
1+
<div id="top-menu" class="top-menu">
2+
<div class="menu-content wrap">
33
<div class="menu-placeholder">
44
<div class="menu-item-container">
55
<div class="menu-items">
66
{{#each menuItems as |item|}}
7-
<a class="menu-item {{item.view}} {{item.className}}" title="{{item.title}}">
7+
<a
8+
class="menu-item {{item.view}} {{item.className}}"
9+
title={{item.title}}
10+
>
811
{{#if item.icon}}
912
{{d-icon item.icon}}
1013
{{/if}}
14+
1115
{{item.text}}
16+
1217
{{#if showCaret}}
1318
{{d-icon "caret-right"}}
1419
{{/if}}
20+
1521
<div class="d-header-dropdown">
1622
<ul class="d-dropdown-menu">
1723
{{#each item.childItems as |child|}}
1824
{{#if child.divider}}
19-
<li class='divider'></li>
25+
<li class="divider"></li>
2026
{{else}}
2127
<li class="submenu-item {{child.className}}">
22-
<a target="{{child.target}}" title="{{child.title}}" class="submenu-link" href="{{child.href}}">
28+
<a
29+
target={{child.target}}
30+
title={{child.title}}
31+
class="submenu-link"
32+
href={{child.href}}
33+
>
2334
{{#if child.icon}}
2435
{{d-icon child.icon}}
2536
{{/if}}
37+
2638
{{child.text}}
2739
</a>
2840
</li>
@@ -36,4 +48,4 @@
3648
</div>
3749
</div>
3850
</div>
39-
</div>
51+
</div>
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
// Used instead of dasherize for backwards compatibility with stable
2-
const getClassName = text => {
2+
const getClassName = (text) => {
33
return text.toLowerCase().replace(/\s/g, "-");
44
};
55

66
export default {
7-
setupComponent(args, component) {
7+
setupComponent() {
88
try {
99
const splitMenuItems = settings.Menu_items.split("|").filter(Boolean);
10-
const splitSubmenuItems = settings.Submenu_items.split("|").filter(
11-
Boolean
12-
);
10+
const splitSubmenuItems =
11+
settings.Submenu_items.split("|").filter(Boolean);
1312

1413
const menuItemsArray = [];
1514
const SubmenuItemsArray = [];
1615

17-
splitSubmenuItems.forEach(item => {
18-
const fragments = item.split(",").map(fragment => fragment.trim());
16+
splitSubmenuItems.forEach((item) => {
17+
const fragments = item.split(",").map((fragment) => fragment.trim());
1918
const parent = fragments[0].toLowerCase();
2019
const text = fragments[1];
2120

2221
if (text.toLowerCase() === "divider") {
2322
const divider = {
2423
parent,
25-
divider: true
24+
divider: true,
2625
};
2726
return SubmenuItemsArray.push(divider);
2827
}
@@ -36,20 +35,20 @@ export default {
3635
const target = fragments[4] === "blank" ? "_blank" : "";
3736
const title = fragments[5];
3837

39-
const submenItem = {
38+
const submenuItem = {
4039
parent,
4140
text,
4241
className,
4342
icon,
4443
href,
4544
target,
46-
title
45+
title,
4746
};
48-
SubmenuItemsArray.push(submenItem);
47+
SubmenuItemsArray.push(submenuItem);
4948
});
5049

51-
splitMenuItems.forEach(item => {
52-
const fragments = item.split(",").map(fragment => fragment.trim());
50+
splitMenuItems.forEach((item) => {
51+
const fragments = item.split(",").map((fragment) => fragment.trim());
5352
const parentFor = fragments[0].toLowerCase();
5453
const text = fragments[0];
5554
const className = getClassName(text);
@@ -60,7 +59,7 @@ export default {
6059
const title = fragments[2];
6160
const view = fragments[3];
6261
const childItems = SubmenuItemsArray.filter(
63-
link => link.parent === parentFor
62+
(link) => link.parent === parentFor
6463
);
6564

6665
const menuItem = {
@@ -69,7 +68,7 @@ export default {
6968
icon,
7069
title,
7170
view,
72-
childItems
71+
childItems,
7372
};
7473
menuItemsArray.push(menuItem);
7574
});
@@ -78,13 +77,14 @@ export default {
7877

7978
this.setProperties({
8079
menuItems: menuItemsArray,
81-
showCaret
80+
showCaret,
8281
});
8382
} catch (error) {
84-
console.error(error);
83+
// eslint-disable-next-line no-console
8584
console.error(
85+
error,
8686
"There's an issue in the Header Submenus Component. Check if your settings are entered correctly"
8787
);
8888
}
89-
}
89+
},
9090
};

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "discourse-header-submenus",
3+
"version": "1.0.0",
4+
"repository": "https://github.com/discourse/discourse-header-submenus",
5+
"author": "Discourse",
6+
"license": "MIT",
7+
"devDependencies": {
8+
"eslint-config-discourse": "^3.2.0"
9+
}
10+
}

0 commit comments

Comments
 (0)