Skip to content

Commit

Permalink
Add provisioning step in GH action (#4)
Browse files Browse the repository at this point in the history
Small provisioning test in Ubuntu container.
  • Loading branch information
femnad authored Dec 9, 2023
1 parent 7f220a9 commit e7d4890
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Run tests

on:
pull_request:
push:
Expand All @@ -8,7 +10,7 @@ on:

jobs:
test:
name: Run tests
name: Run unit and integration tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -20,3 +22,21 @@ jobs:
run: |
go install
python3 tests/test_archives.py
container-test:
name: Run provisioning in a container
runs-on: ubuntu-latest
container:
image: ubuntu:mantic
steps:
- uses: actions/checkout@v4

- name: Setup container
run: |
apt update
apt install -y ca-certificates curl gnupg2 golang
go install
- name: Provision
run: |
~/go/bin/fup -f contrib/test.yml -b
46 changes: 46 additions & 0 deletions contrib/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
settings:
extract_dir: ext
versions:
chezmoi: 2.42.2

preflight:
- task: Enable Docker repo (Debian|Ubuntu)
when: is-debian is-ubuntu
unless:
stat: /etc/apt/sources.list.d/docker.list
steps:
- name: shell
shell: bash
cmd: |
set -euEo pipefail
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list
apt update
packages:
debian|ubuntu:
- docker-buildx-plugin
- docker-ce
- docker-ce-cli
- docker-compose-plugin

archives:
- url: https://github.com/twpayne/chezmoi/releases/download/v${version}/chezmoi_${version}_linux_amd64.tar.gz
name: chezmoi
unless:
cmd: chezmoi --version
post: split 2 | cut 1 | cut -1

tasks:
- task: Clone chezmoi
unless:
stat: ~/.local/share/chezmoi
steps:
- name: git
repo:
name: https://gitlab.com/femnad/chezmoi.git
dir: ~/.local/share/chezmoi
- name: cmd
cmd: ~/bin/chezmoi apply --force
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {

err = p.Apply()
if err != nil {
fmt.Printf("Some provisioners had errors: %v", err)
fmt.Printf("Some provisioners had errors: %v\n", err)
os.Exit(1)
}
}
9 changes: 7 additions & 2 deletions precheck/fact.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ func neovimReady() (bool, error) {
}

func sshReady() (bool, error) {
resp, _ := marecmd.RunFormatError(marecmd.Input{Command: "ssh-add -l"})
if resp.Code == 1 {
resp, err := marecmd.RunFormatError(marecmd.Input{Command: "ssh-add -l"})
if err != nil {
internal.Log.Debugf("error checking ssh-add output: %v", err)
return false, nil
}

output := strings.TrimSpace(resp.Stdout)
if output == "" {
return false, nil
}

for _, line := range strings.Split(output, "\n") {
fields := strings.Split(line, " ")
if len(fields) != 4 {
Expand Down

0 comments on commit e7d4890

Please sign in to comment.