-
Notifications
You must be signed in to change notification settings - Fork 1
134 lines (114 loc) · 3.89 KB
/
test.yml
File metadata and controls
134 lines (114 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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: DeterminateSystems/nix-installer-action@main
with:
determinate: true
extra-conf: "lazy-trees = true"
# Use the cachix cache for faster builds.
- name: Cachix Init
uses: cachix/cachix-action@v15
with:
name: digitallyinduced
skipPush: true
# # Initialize custom cachix for pushing
# - name: Custom Cachix Init
# uses: cachix/cachix-action@v15
# with:
# name: CHANGE-ME
# authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
# skipPush: true
# Free up disk space before building
- name: Free disk space
run: |
# @see https://github.com/actions/runner-images/issues/2840#issuecomment-1284059930
# IHP - NixOS requires a lots of disk space.
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /opt/hostedtoolcache
sudo docker system prune -af
# Pre-build shell environment to speed up direnv
- name: Pre-build shell environment
run: |
nix develop --impure --accept-flake-config --profile dev-profile -c true
# Install direnv, which also `direnv allow`s the project.
- uses: HatsuneMiku3939/direnv-action@v1.1.0
with:
direnvVersion: 2.32.3
- name: Run project and tests
run: |
# Build generated files.
make build/Generated/Types.hs
# Start the project in the background.
devenv up &
# Wait for the IHP server to start.
timeout=60
while [ $timeout -gt 0 ]; do
if curl -s http://localhost:8000 >/dev/null 2>&1; then
echo "IHP server is ready!"
break
fi
sleep 1
timeout=$((timeout - 1))
done
if [ $timeout -eq 0 ]; then
echo "Timeout waiting for IHP server to start"
exit 1
fi
# Execute the tests.
runghc $(make print-ghc-extensions) -i. -ibuild -iConfig Test/Main.hs
# Push to cachix after successful tests
# - name: Push to Cachix
# if: github.ref == 'refs/heads/main'
# run: |
# nix build --no-link --json .#nixosConfigurations.qa.config.system.build.toplevel | jq -r '.[].outputs.out' | cachix push CHANGE-ME
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 }}