2023-01-10 14:21:38 +00:00
# Contributing to semaphore
2018-03-31 01:55:55 +01:00
2023-01-21 13:34:01 +00:00
## Building
Semaphore requires [Node.js ](https://nodejs.org/en/ ) and [Yarn ](https://yarnpkg.com ).
To build Semaphore for production, first install dependencies:
yarn --production --pure-lockfile
Then build:
yarn build
Then run:
PORT=4002 node server.js
### Docker
To build a Docker image for production:
docker build .
docker run -d -p 4002:4002 [your-image]
Now Semaphore is running at `localhost:4002` .
### docker-compose
Alternatively, use docker-compose to build and serve the image for production:
docker-compose up --build -d
The image will build and start, then detach from the terminal running at `localhost:4002` .
### Updating
To keep your version of Semaphore up to date, you can use `git` to check out the latest tag:
git checkout $(git tag -l | sort -Vr | head -n 1)
### Exporting
Semaphore is a static site. When you run `yarn build` , static files will be
written to `__sapper__/export` .
It is _not_ recommended to directly expose these files when self-hosting. Instead, you should use `node server.js` (e.g. with an
nginx or Apache proxy in front). This adds several things you don't get from the raw static files:
- [CSP headers ](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP ) (important for security)
- Certain dynamic routes (less important because of Service Worker managing routing, but certain things could break if Service Workers are disabled in the user's browser)
2019-03-02 22:44:19 +00:00
## Installing
To install with dev dependencies, run:
yarn
2018-12-19 08:57:48 +00:00
## Dev server
2018-03-31 01:55:55 +01:00
To run a dev server with hot reloading:
2019-01-28 01:44:30 +00:00
yarn run dev
2018-03-31 01:55:55 +01:00
Now it's running at `localhost:4002` .
2020-04-26 03:03:39 +01:00
**Linux users:** for file changes to work,
2018-12-18 01:21:29 +00:00
you'll probably want to run `export CHOKIDAR_USEPOLLING=1`
because of [this issue ](https://github.com/paulmillr/chokidar/issues/237 ).
2018-03-31 01:55:55 +01:00
## Linting
2023-01-10 14:21:38 +00:00
semaphore uses [JavaScript Standard Style ](https://standardjs.com/ ).
2018-03-31 01:55:55 +01:00
Lint:
2019-01-28 01:44:30 +00:00
yarn run lint
2018-03-31 01:55:55 +01:00
Automatically fix most linting issues:
2019-01-28 01:44:30 +00:00
yarn run lint-fix
2018-03-31 01:55:55 +01:00
2018-12-19 08:57:48 +00:00
## Integration tests
Integration tests use [TestCafé ](https://devexpress.github.io/testcafe/ ) and a live local Mastodon instance
running on `localhost:3000` .
### Running integration tests
2018-03-31 01:55:55 +01:00
2018-12-19 08:57:48 +00:00
The integration tests require running Mastodon itself,
2022-12-02 19:14:32 +00:00
meaning the [Mastodon development guide ](https://docs.joinmastodon.org/dev/setup/ )
2020-04-26 03:03:39 +01:00
is relevant here. In particular, you'll need a recent
2018-12-19 08:57:48 +00:00
version of Ruby, Redis, and Postgres running. For a full list of deps, see `bin/setup-mastodon-in-travis.sh` .
2018-04-12 17:44:02 +01:00
2018-03-31 01:55:55 +01:00
Run integration tests, using headless Chrome by default:
npm test
Run tests for a particular browser:
2019-01-28 01:44:30 +00:00
BROWSER=chrome yarn run test-browser
BROWSER=chrome:headless yarn run test-browser
BROWSER=firefox yarn run test-browser
BROWSER=firefox:headless yarn run test-browser
BROWSER=safari yarn run test-browser
BROWSER=edge yarn run test-browser
2018-03-31 01:55:55 +01:00
2018-12-30 22:50:51 +00:00
If the script isn't able to set up the Postgres database, try running:
sudo su - postgres
Then:
2023-01-10 14:21:38 +00:00
psql -d template1 -c "CREATE USER semaphore WITH PASSWORD 'semaphore' CREATEDB;"
2018-12-30 22:50:51 +00:00
2018-12-19 08:57:48 +00:00
### Testing in development mode
2018-03-31 01:55:55 +01:00
In separate terminals:
1\. Run a Mastodon dev server:
2019-01-28 01:44:30 +00:00
yarn run run-mastodon
2018-03-31 01:55:55 +01:00
2023-01-10 14:21:38 +00:00
2\. Run a Semaphore dev server:
2018-03-31 01:55:55 +01:00
2019-01-28 01:44:30 +00:00
yarn run dev
2018-03-31 01:55:55 +01:00
3\. Run a debuggable TestCafé instance:
2019-11-09 22:25:33 +00:00
npx testcafe --debug-mode chrome tests/spec
2018-03-31 01:55:55 +01:00
2018-12-19 08:57:48 +00:00
### Test conventions
2018-03-31 01:55:55 +01:00
2018-12-19 08:57:48 +00:00
The tests have a naming convention:
2018-04-12 04:33:34 +01:00
2018-12-19 08:57:48 +00:00
* `0xx-test-name.js` : tests that don't modify the Mastodon database (read-only)
* `1xx-test-name.js` : tests that do modify the Mastodon database (read-write)
2018-04-12 04:33:34 +01:00
In principle the `0-` tests don't have to worry about
2018-04-12 17:44:02 +01:00
clobbering each other, whereas the `1-` ones do.
2018-05-02 01:00:34 +01:00
2018-12-19 08:57:48 +00:00
### Mastodon used for testing
2018-05-02 01:00:34 +01:00
2018-12-19 08:57:48 +00:00
There are two parts to the Mastodon data used for testing:
2018-05-02 01:00:34 +01:00
2018-12-19 08:57:48 +00:00
1. A Postgres dump and a tgz containing the media files, located in `fixtures`
2. A script that populates the Mastodon backend with test data (`restore-mastodon-data.js`).
2018-05-02 01:00:34 +01:00
2020-04-26 03:03:39 +01:00
The reason we don't use a Postgres dump for everything
2018-12-19 08:57:48 +00:00
is that Mastodon will ignore changes made after a certain period of time, and we
don't want our tests to randomly start breaking one day. Running the script ensures that statuses,
favorites, boosts, etc. are all "fresh".
### Updating the test data
You probably don't want to do this, as the `0xx` tests are pretty rigidly defined against the test data.
Write a `1xx` test instead and insert what you need on-the-fly.
If you really need to, though, you can either:
1. Add new test data to `mastodon-data.js`
or
2018-06-07 23:26:47 +01:00
2018-12-19 08:57:48 +00:00
1. Comment out `await restoreMastodonData()` in `run-mastodon.js`
2. Make your changes manually to the live Mastodon
3. Run the steps in the next section to back it up to `fixtures/`
### Updating the Mastodon version
2018-06-07 23:26:47 +01:00
1. Run `rm -fr mastodon` to clear out all Mastodon data
1. Comment out `await restoreMastodonData()` in `run-mastodon.js` to avoid actually populating the database with statuses/favorites/etc.
2022-11-25 19:04:37 +00:00
2. Update the `GIT_TAG` in `mastodon-config.js` to whatever you want
3. If the Ruby version changed (check Mastodon's `.ruby-version` ), install it and update `RUBY_VERSION` in `mastodon-config.js` as well as the Ruby version in `.github/workflows` .
2020-05-03 02:02:29 +01:00
4. Run `yarn run-mastodon`
5. Run `yarn backup-mastodon-data` to overwrite the data in `fixtures/`
6. Uncomment `await restoreMastodonData()` in `run-mastodon.js`
7. Commit all changed files
8. Run `rm -fr mastodon/` and `yarn run run-mastodon` to confirm everything's working
2018-06-07 23:26:47 +01:00
2018-11-20 08:01:23 +00:00
Check `mastodon.log` if you have any issues.
2019-05-05 23:02:14 +01:00
Note that we also run `db:migrate` just to play it safe, but
updating the `fixtures/` should make that a no-op.
2018-11-20 08:01:23 +00:00
## Unit tests
There are also some unit tests that run in Node using Mocha. You can find them in `tests/unit` and
2019-01-28 01:44:30 +00:00
run them using `yarn run test-unit` .
2018-12-19 08:57:48 +00:00
2019-09-21 21:44:32 +01:00
## Debug build
To disable minification in a production build (for debugging purposes), you can run:
DEBUG=1 yarn build
2018-12-19 08:57:48 +00:00
## Debugging Webpack
The Webpack Bundle Analyzer `report.html` and `stats.json` are available publicly via e.g.:
2023-01-10 14:22:26 +00:00
- [beta.semaphore.social/report.html ](https://beta.semaphore.social/report.html )
- [beta.semaphore.social/stats.json ](https://beta.semaphore.social/stats.json )
2018-12-19 08:57:48 +00:00
2019-01-28 01:44:30 +00:00
This is also available locally after `yarn run build` at `.sapper/client/report.html` .
2018-12-19 08:57:48 +00:00
2021-02-14 22:01:52 +00:00
## Deploying
2018-12-19 08:57:48 +00:00
2023-01-10 14:22:26 +00:00
This section only applies to `beta.semaphore.social` and `semaphore.social` , not if you're hosting your own version of
2023-01-10 14:21:38 +00:00
Semaphore.
2018-12-19 08:57:48 +00:00
2023-01-10 14:24:37 +00:00
The site uses [Vercel ](https://vercel.com ). The `main` branch publishes to `beta.semaphore.social` and the `production`
2023-01-10 14:21:38 +00:00
branch deploys to `semaphore.social` .
2018-12-19 08:57:48 +00:00
2021-02-14 22:01:52 +00:00
## Architecture
2018-12-19 08:57:48 +00:00
2023-01-22 09:08:20 +00:00
See [Architecture.md ](https://github.com/NickColley/semaphore/blob/main/docs/Architecture.md ).
2018-12-19 08:57:48 +00:00
2021-02-14 22:01:52 +00:00
## Internationalization
2018-12-19 08:57:48 +00:00
2023-01-22 09:08:20 +00:00
See [Internationalization.md ](https://github.com/NickColley/semaphore/blob/main/docs/Internationalization.md ).
2018-12-19 08:57:48 +00:00