Skip to content

Commit 7b359e3

Browse files
authored
DEV: Add CI setup (#7)
1 parent 26d7204 commit 7b359e3

File tree

10 files changed

+2161
-3
lines changed

10 files changed

+2161
-3
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

.github/workflows/component-tests.yml

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Icon Header Links",
3+
"component": true,
34
"about_url": "https://meta.discourse.org/t/custom-header-links-icons/86307",
4-
"license_url": "https://github.com/discourse/discourse-icon-header-links/blob/main/LICENSE",
5-
"component": true
5+
"license_url": "https://github.com/discourse/discourse-icon-header-links/blob/main/LICENSE"
66
}

javascripts/discourse/initializers/initialize-for-header-icon-links.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ export default {
4040
});
4141
});
4242
} catch (error) {
43-
console.error(error);
43+
// eslint-disable-next-line no-console
4444
console.error(
45+
error,
4546
"There's an issue in the header icon links component. Check if your settings are entered correctly"
4647
);
4748
}

package.json

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

0 commit comments

Comments
 (0)