|
| 1 | +# Deploying to GitHub Pages |
| 2 | + |
| 3 | +GitHub Pages can host the static files that Tableau produces. This guide walks through a production-ready setup that you can adopt for your own site. |
| 4 | + |
| 5 | +## Prepare your Tableau project |
| 6 | + |
| 7 | +1. Set the production `url` in `config/prod.exs` (your custom domain or the full GitHub Pages URL): |
| 8 | + |
| 9 | + ```elixir |
| 10 | + # config/prod.exs |
| 11 | + config :tableau, :config, |
| 12 | + url: "https://your-domain.tld" |
| 13 | + ``` |
| 14 | + |
| 15 | +2. If you serve additional assets (Tailwind, esbuild, etc.), add the corresponding Mix tasks to the `build` alias so they also run in CI. |
| 16 | + |
| 17 | +## Add the GitHub Pages workflow |
| 18 | + |
| 19 | +Create `.github/workflows/deploy.yml` with the following workflow. It installs Erlang/OTP + Elixir, builds the site in production mode, and publishes the `_site` directory to GitHub Pages: |
| 20 | + |
| 21 | +```yaml |
| 22 | +name: Deploy site to GitHub Pages |
| 23 | + |
| 24 | +on: |
| 25 | + push: |
| 26 | + branches: [main] |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + pages: write |
| 31 | + id-token: write |
| 32 | + |
| 33 | +concurrency: |
| 34 | + group: pages |
| 35 | + cancel-in-progress: true |
| 36 | + |
| 37 | +jobs: |
| 38 | + build: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v5 |
| 43 | + |
| 44 | + - name: Set up Erlang/OTP and Elixir |
| 45 | + uses: erlef/setup-beam@v1 |
| 46 | + with: |
| 47 | + otp-version: "28" |
| 48 | + elixir-version: "1.18" |
| 49 | + |
| 50 | + - name: Cache Mix deps |
| 51 | + uses: actions/cache@v4 |
| 52 | + with: |
| 53 | + path: | |
| 54 | + ~/.mix |
| 55 | + deps |
| 56 | + _build |
| 57 | + key: ${{ runner.os }}-otp-28-elixir-1.18-mix-${{ hashFiles('**/mix.lock') }} |
| 58 | + restore-keys: | |
| 59 | + ${{ runner.os }}-otp-28-elixir-1.18-mix- |
| 60 | +
|
| 61 | + - name: Install dependencies |
| 62 | + run: MIX_ENV=prod mix deps.get --only prod |
| 63 | + |
| 64 | + - name: Build site |
| 65 | + run: MIX_ENV=prod mix build |
| 66 | + |
| 67 | + - name: Upload artifact |
| 68 | + uses: actions/upload-pages-artifact@v4 |
| 69 | + with: |
| 70 | + path: _site |
| 71 | + |
| 72 | + deploy: |
| 73 | + environment: |
| 74 | + name: github-pages |
| 75 | + url: ${{ steps.deployment.outputs.page_url }} |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: build |
| 78 | + steps: |
| 79 | + - id: deployment |
| 80 | + uses: actions/deploy-pages@v4 |
| 81 | +``` |
| 82 | +
|
| 83 | +### Workflow notes |
| 84 | +
|
| 85 | +- Set `otp-version` and `elixir-version` to match your project. |
| 86 | +- Update the cache key when you bump OTP or Elixir so a fresh build occurs. |
| 87 | +- If `mix build` already chains your asset pipelines, no other changes are needed. Otherwise, insert additional steps before "Upload artifact". |
| 88 | +- The cache step speeds up successive runs but can be removed if you prefer. |
| 89 | + |
| 90 | +## Enable GitHub Pages |
| 91 | + |
| 92 | +1. Push the workflow to your default branch (the example uses `main`). |
| 93 | +2. In your repository, open **Settings → Pages**. |
| 94 | +3. Under **Build and deployment**, choose **GitHub Actions**. |
| 95 | +4. After the first successful run, the deployment will appear under the **Deployments** tab and the workflow output prints the public URL. |
| 96 | + |
| 97 | +## Custom domains & pages.io URLs |
| 98 | + |
| 99 | +If you have a custom domain: |
| 100 | + |
| 101 | +- Add a `CNAME` file at the repo root containing the domain, e.g. `example.com`. |
| 102 | +- Configure your DNS to point at GitHub Pages. |
| 103 | +- Keep `config :tableau, :config, url: "https://your-domain"` in sync so absolute links are generated correctly. |
| 104 | +- GitHub’s docs cover the DNS details in depth: <https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/about-custom-domains-and-github-pages>. |
| 105 | +
|
| 106 | +If you deploy to `<user>.github.io/<repo>`, use the full Pages URL (e.g. `https://username.github.io/my-site`) and optionally set `base_path: "/my-site"` in `config/prod.exs` so local links match production. |
| 107 | + |
| 108 | +## Troubleshooting |
| 109 | + |
| 110 | +- See a 404 for nested routes? Double-check `base_path` in `config/prod.exs` when deploying under a subdirectory. |
| 111 | +- Need to rebuild assets? Append those build steps to the `build` alias so `mix build` runs everything locally and in CI. |
| 112 | +- Want to test locally? Run `MIX_ENV=prod mix build` and inspect the output directory (which defaults to `_site/`) before pushing. |
| 113 | + |
| 114 | +With these pieces in place, every push to `main` rebuilds your Tableau site and deploys it to GitHub Pages. |
0 commit comments