sensu / sensu-go-chef

Chef Library Cookbook for Sensu Go
https://sensu.io
MIT License
11 stars 22 forks source link

Add windows github action workflow #123

Open webframp opened 3 years ago

webframp commented 3 years ago

At the moment I don't believe this will work because it depends on services which require a runs-on value of a linux host.

Opening this as a draft PR just to track attempts at solving this.


Pull Request Checklist

Is this in reference to an existing issue?

Yes, #68

General

New Features

Purpose

Add a GH Action for testing the windows agent in CI

Known Compatibility Issues

In cookbook none. With GH Actions, service containers aren't supported on windows runners.

webframp commented 3 years ago

Known issue right now that services with GH Actions requires linux:

Error: Container operations are only supported on Linux runners
webframp commented 3 years ago

Hey @derekgroh I don't have any great ideas for how best to handle this, but if you have experience with windows + GH Actions feel free to push fixes to this branch with ideas.

derekgroh commented 3 years ago

@webframp Not really, just started trying to play with it. We can try to connect on Slack and maybe figure it out.

derekgroh commented 3 years ago

@webframp Can you allow me to push against this branch?

majormoses commented 3 years ago

@derekgroh I think there are several options and it depends on what you want to do:

I am going to write up an issue to better outline what being a maintainer should look like.

webframp commented 3 years ago

@derekgroh Feel free to open something new based on this branch too, I don't do a lot with Windows these days so this is just sort of a brain dump.

I have no problem closing and not merging this.

derekgroh commented 3 years ago

Here's what I was able to work out.

Target:  winrm://vagrant@http://172.26.145.20:5985/wsman:3389

  Command: `cmd.exe /c "echo %PATH%"`
     [PASS]  stdout is expected to include "c:\\Program Files\\Sensu\\sensu-cli\\bin\\sensuctl"
  File c:\Program Files\Sensu\sensu-cli\bin\sensuctl\sensuctl.exe
     [PASS]  is expected to exist
  Command: `sensuctl entity list`
     [PASS]  stdout is expected to match /backend/
     [PASS]  exit_status is expected to eq 0

Test Summary: 4 successful, 0 failures, 0 skipped
       Finished verifying <ctl-windows-2019> (0m9.35s).
-----> Test Kitchen is finished. (5m50.69s)
---
name: windows

"on":
  pull_request:
  push:
    branches:
      - master

jobs:
  windows_agent:
    runs-on: windows-latest
    steps:
      - name: Check out code
        uses: actions/checkout@master
      - name: Install Chef
        uses: actionshub/chef-install@master
      - name: Create directory
        run: mkdir D:\a\berks-cookbooks\
      - name: Create Link
        run: cmd /c mklink /d  D:\a\cookbooks\ D:\a\berks-cookbooks\         
      - name: Berks
        working-directory: D:\a\
        run: berks vendor -b D:\a\sensu-go-chef\sensu-go-chef\Berksfile
      - name: Chef Zero
        working-directory: D:\a\cookbooks\sensu-go\
        env:
         CHEF_LICENSE: accept-no-persist
        run: chef-client -z -o sensu_test::agent
      - name: Verify
        run: chef exec inspec exec D:\a\sensu-go-chef\sensu-go-chef\test\integration\agent\agent_spec.rb
        env:
         CHEF_LICENSE: accept-no-persist     
  windows_ctl:
    runs-on: windows-latest
    steps:
      - name: Check out code
        uses: actions/checkout@master
      - name: Install Chef
        uses: actionshub/chef-install@master
      - name: Create directory
        run: mkdir D:\a\berks-cookbooks\
      - name: Create Link
        run: cmd /c mklink /d  D:\a\cookbooks\ D:\a\berks-cookbooks\         
      - name: Berks
        working-directory: D:\a\
        run: berks vendor -b D:\a\sensu-go-chef\sensu-go-chef\Berksfile
      - name: Chef Zero
        working-directory: D:\a\cookbooks\sensu-go\
        env:
         CHEF_LICENSE: accept-no-persist
        run: chef-client -z -o sensu_test::ctl
      # - name: Verify
        # run: chef exec inspec exec D:\a\sensu-go-chef\sensu-go-chef\test\integration\ctl\ctl_spec.rb
        # env:
         # CHEF_LICENSE: accept-no-persist

The ctl job fails out with the path and backend not matching, where as test kitchen detects them correctly (see above). This seems like an environment issue with the platform GitHub is using, but I can't be sure.

Not sure if the ctl run should be removed or how best to test, I've also changed the test to and list backends instead of users

sensu_ctl 'default' do
  action [:install, :configure]
  username 'guest'
  password 'i<3sensu'
  backend_url 'https://caviar.tf.sensu.io:8080/'
  debug true
end

This allows ctl testing against a running backend, which should always be available