updated index view #7
This file contains hidden or 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
| 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 }} |