-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from james64/elm
Bring `elm` branch up-to-date with `master` to fix ihp-new for elm
- Loading branch information
Showing
11 changed files
with
1,602 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then | ||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8=" | ||
fi | ||
|
||
use flake . --impure --accept-flake-config | ||
|
||
# Include .env file if it exists locally. Use the .env file to load env vars that you don't want to commit to git | ||
if [ -f .env ] | ||
then | ||
set -o allexport | ||
source .env | ||
set +o allexport | ||
fi | ||
# Add your env vars here | ||
# | ||
# E.g. export AWS_ACCESS_KEY_ID="XXXXX" | ||
|
||
# SMTP config for local development. | ||
export SMTP_HOST="127.0.0.1" # On some computers may need `127.0.1.1` instead. | ||
export SMTP_PORT="1025" | ||
export SMTP_ENCRYPTION="Unencrypted" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
:set -XNoImplicitPrelude | ||
:def source readFile | ||
:source build/ihp-lib/applicationGhciConfig | ||
import IHP.Prelude | ||
:def loadFromIHP \file -> (System.Environment.getEnv "IHP_LIB") >>= (\ihpLib -> readFile (ihpLib <> "/" <> file)) | ||
:loadFromIHP applicationGhciConfig | ||
import IHP.Prelude |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: Test and Deploy | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the main branch | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
env: | ||
ENV: "qa" | ||
PROJECT_NAME: myproject | ||
SSH_HOST: ${{ secrets.SSH_HOST }} | ||
SSH_USER: ${{ secrets.SSH_USER }} | ||
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
NIXPKGS: "https://github.com/NixOS/nixpkgs/archive/51bcdc4cdaac48535dabf0ad4642a66774c609ed.tar.gz" | ||
|
||
jobs: | ||
tests: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: cachix/install-nix-action@v27 | ||
with: | ||
nix_path: nixpkgs=${{ env.NIXPKGS}} | ||
|
||
# Use the cachix cache for faster builds. | ||
- name: Cachix Init | ||
uses: cachix/cachix-action@v15 | ||
with: | ||
name: digitallyinduced | ||
skipPush: true | ||
|
||
# Install direnv, which also `direnv allow`s the project. | ||
- uses: HatsuneMiku3939/[email protected] | ||
with: | ||
direnvVersion: 2.32.3 | ||
|
||
- name: Run project and tests | ||
run: | | ||
# @see https://github.com/actions/runner-images/issues/2840#issuecomment-1284059930 | ||
# IHP - NixOS requires a lots of disk space. | ||
# Larger projects could easily run into unexpected failures. | ||
sudo rm -rf /usr/share/dotnet | ||
sudo rm -rf "$AGENT_TOOLSDIRECTORY" | ||
# Build generated files. | ||
nix-shell --run "make build/Generated/Types.hs" | ||
# Start the project in the background. | ||
nix-shell --run "devenv up &" | ||
# Execute the tests. | ||
nix-shell --run "runghc $(make print-ghc-extensions) -i. -ibuild -iConfig Test/Main.hs" | ||
deploy: | ||
name: Deploy | ||
needs: tests | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup SSH | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ env.SSH_KEY }}" > ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
ssh-keyscan -H ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts | ||
echo -e "Host ${{ env.PROJECT_NAME}}-${{ env.ENV }}\n HostName ${{ env.SSH_HOST }}\n User ${{ env.SSH_USER }}\n IdentityFile ~/.ssh/id_rsa" > ~/.ssh/config | ||
chmod 600 ~/.ssh/config | ||
- uses: cachix/install-nix-action@v20 | ||
with: | ||
nix_path: nixpkgs=${{ env.NIXPKGS}} | ||
|
||
- name: Cachix Init | ||
uses: cachix/cachix-action@v12 | ||
with: | ||
name: digitallyinduced | ||
skipPush: true | ||
|
||
- uses: HatsuneMiku3939/direnv-action@v1 | ||
with: | ||
direnvVersion: 2.32.3 | ||
|
||
- name: Deploy | ||
run: | | ||
deploy-to-nixos ${{ env.PROJECT_NAME}}-${{ env.ENV }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# IHP Project | ||
|
||
This is an IHP (Integrated Haskell Platform) project with GitHub Actions for testing and deployment. For more information about IHP, see the [IHP Documentation](https://ihp.digitallyinduced.com/Guide/). | ||
|
||
## GitHub Actions Workflow | ||
|
||
This project includes a GitHub Actions workflow for automated testing and deployment. The workflow is defined in `.github/workflows/test.yml`. | ||
|
||
### Workflow Triggers | ||
|
||
The workflow is triggered on: | ||
- Push to the `main` branch | ||
- Pull requests to the `main` branch | ||
- Manual trigger from the GitHub Actions tab | ||
|
||
### Testing | ||
|
||
The testing job performs the following steps: | ||
1. Checks out the code | ||
2. Sets up Nix | ||
3. Initializes Cachix for faster builds | ||
4. Installs and allows direnv | ||
5. Builds generated files | ||
6. Starts the project in the background | ||
7. Runs the tests | ||
|
||
### Deployment | ||
|
||
For deployment, follow the [IHP Deployment Guide](https://ihp.digitallyinduced.com/Guide/deployment.html#deploying-with-deploytonixos) to set up a proper NixOS server for your project. | ||
|
||
The deployment job runs after successful tests and only for the `main` branch. It performs the following steps: | ||
1. Checks out the code | ||
2. Sets up SSH for deployment | ||
3. Sets up Nix | ||
4. Initializes Cachix | ||
5. Sets up direnv | ||
6. Deploys to a NixOS server | ||
|
||
## Setup Instructions | ||
|
||
To use the GitHub Actions workflow in this project: | ||
|
||
1. Set up the following secrets in your GitHub [repository settings](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions): | ||
- `SSH_HOST`: The hostname or IP address of your deployment server | ||
- `SSH_USER`: The username for SSH access to the deployment server | ||
- `SSH_PRIVATE_KEY`: The private SSH key for authentication | ||
|
||
2. Modify the `env` section in `.github/workflows/test.yml` if needed: | ||
- Update `PROJECT_NAME` to match your project | ||
- Adjust `ENV` if you want to use a different environment name | ||
- Update `NIXPKGS` if you want to use a different Nixpkgs version | ||
|
||
3. Ensure your project has the necessary test files in the `Test` directory. | ||
|
||
4. If your deployment process differs, modify the `deploy` job in the workflow file accordingly. | ||
|
||
5. Push your changes to the `main` branch to trigger the workflow. | ||
|
||
## Manual Workflow Trigger | ||
|
||
You can manually trigger the workflow from the Actions tab in your GitHub repository. This is useful for running tests or deploying without pushing changes. | ||
|
||
## Customization | ||
|
||
Feel free to customize the workflow file to fit your specific project needs. You may want to add additional steps, change the deployment process, or modify the testing procedure. | ||
|
||
## Support | ||
|
||
For issues related to IHP or this project's setup, please refer to the [IHP documentation](https://ihp.digitallyinduced.com/Guide/) or seek help on the [IHP Forum](https://ihp.digitallyinduced.com/community/). | ||
|
||
For project-specific issues, please open an issue in this repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,9 @@ | ||
let | ||
ihp = builtins.fetchGit { | ||
url = "https://github.com/digitallyinduced/ihp.git"; | ||
ref = "refs/tags/v1.0.1"; | ||
}; | ||
haskellEnv = import "${ihp}/NixSupport/default.nix" { | ||
ihp = ihp; | ||
haskellDeps = p: with p; [ | ||
cabal-install | ||
base | ||
wai | ||
text | ||
hlint | ||
p.ihp | ||
]; | ||
otherDeps = p: with p; [ | ||
# Native dependencies, e.g. imagemagick | ||
nodejs | ||
elmPackages.elm | ||
]; | ||
projectPath = ./.; | ||
}; | ||
in | ||
haskellEnv | ||
# For backwards compatibility using flake.nix | ||
(import | ||
( | ||
fetchTarball { | ||
url = "https://github.com/edolstra/flake-compat/archive/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9.tar.gz"; | ||
sha256 = "sha256:1prd9b1xx8c0sfwnyzkspplh30m613j42l1k789s521f4kv4c2z2"; | ||
} | ||
) | ||
{ src = ./.; }).defaultNix |
Oops, something went wrong.