Travis error with HACS (HA Community Store)

However, I now have a problem with getting my Home Assistant config to pass testing on travis-ci.org. Like some other users I share and backup my config up to GitHub. When my new code hits GitHub, Travis goes to work testing the code for errors.

Since I installed HACS Travis reports an error Integration not found: hacs. My repository already contains the /custom_components/hacs folder and code, so I would expect hass on travis to see that component’s code.

Taking a step back, it was a struggle to get HACS installed properly. To get it working I had to place the hacs: definition in my configuration.yaml as a top-level component. It had to be at the same depth as homeassistant: to work properly, which shocked me and still doesn’t seem right. Could that be the problem? The component’s author doesn’t think the problem is related to his component, so here I am asking the community. :slight_smile:


Here is my .travis.yml file:

language: python
python: "3.6.4"
before_install:
  - mv ./travis_secrets.yaml ./secrets.yaml
  - rm -f ./packages/stream.yaml
install:
  - pip3 install homeassistant
script:
  - hass -c ./ --script check_config --info all

I ran the same check_config script that runs on Travis, on my server and it does not return the same error. (The hass -c ./ --script check_config --info all line.)

That’s not the Travis file in your repo, you’ve got

language: python
python: "3.6.4"
before_install:
  - mv ./travis_secrets.yaml ./secrets.yaml
  - rm -f ./packages/stream.yaml
  - cd custom_components
  - git clone https://github.com/custom-components/hacs.git hacs_temp
  - cd hacs_temp
  - git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
  - cd ../
  - cp -r hacs_temp/custom_components/hacs hacs
  - rm -rf hacs_temp
  - cd ../
install:
  - pip3 install homeassistant
script:
  - hass -c ./ --script check_config --info all

Which is a mega mess tbh.

@anon43302295 The code in my original post above is where I started.

The error remained the same regardless of the inclusion of those commands you discovered. I tried to work around the problem by adding the HACS terminal installation instructions. But the hacs code is already available in the custom_components folder, so it isn’t necessary and did not help.

I removed this explanation from the original post to keep from confusing the situation. Since it now has, I have removed it from my repo. As far as it being a mess. Yeah, troubleshooting can be messy. Had it worked I would have put in a bash script and collapsed it to a single line in the .travis file.

hacs updates a lot… i don’t want that many files changing with every commit. So i just removed it from the travis configuration. Just add this oneliner :wink:

sed -e '/hacs/,+2d' < configuration.yaml > configuration.yaml

As seen in my config https://github.com/riemers/home-assistant-config/blob/368ed52c06b994573b7582c594cd95542d6b445c/.travis.yml

1 Like

I am very intrigued by this solution. I vaguely aware of sed, but I have never used it.

So, if I copy configuration.yaml to test.yaml, and then run sed -e '/hacs/,+4d' < temp.yaml it outputs my config, without the hacs: section. Great. Unfortunately, adding the > temp.yaml to the end causes the temp.yaml to be emptied.

Here are the commands in order to replicate this. (I am preforming the sed command on my Ubuntu Server before I add it to my .travis file.)

# cp configuration.yaml temp.yaml
# sed -e '/hacs/,+4d' < temp.yaml > temp.yaml

@riemers Update: I tried piping the output to a temporary .yaml file and it works.

# sed -e '/hacs/,+4d' < configuration.yaml > temp.yaml
# cat temp.yaml

On Ubuntu Server I can replicate what you intended by doing this:

# sed -e '/hacs/,+4d' < configuration.yaml > temp.yaml
# cp temp.yaml configuration.yaml

I think I am going to try your original format on .travis… but if it doesn’t work, then I have an alternate way to accomplish it. Thank you.


30 minutes later…

It worked! Thank you very much @riemers!

Your welcome :+1:

This has to be done for each hacs-installed custom component that requires some yaml configuration.
In the end you’ll be testing some parts of your config, but not the whole config anymore.

Would be great if there would be a proper solution to make travis install hacs and the required components. @ludeeus any chance to get this working? Any best practices?

Thanks.

The newest version of HACS can be added via the UI (Configuration -> Integrations). First, remove the hacs: section from configuration.yaml, then restart and add HACS via “Integrations”.

So this workaround is no longer necessary!

Unfortunately this is only right if all components installed via have are also set up with the UI integration.
If there’s only a single one that’s using yaml setup, the check will fail.

No, this has to be done for all custom_components, no matter how you “install” them.
HACS “is just a downloader”.

You can try adding this as a script that runs before your checks.

for file in $(find custom_components/ -name "manifest.json"); do cat "$file" | for req in $(jq .requirements[]); do python3 -m pip install $(echo "$req" | jq -r .) ; done ; done

With that said, If it where me I would have the YAML for all custom_components in a single package, and just add the entire custom_components dir and that package file to my .gitignore file

That way I’m not republishing these (sometimes huge) custom_components.

1 Like

If you have GitHub actions enabled on your repo, you can use this:
https://github.com/custom-components/hacs/blob/ea76852d94f870ecbb2021c6c4ed894a4b2cfa0e/.github/workflows/test_with_home_assistant.yml
Or a slightly modified version, since you will not have to inject the config, and will probably not need to run against dev

example output: https://github.com/custom-components/hacs/commit/ea76852d94f870ecbb2021c6c4ed894a4b2cfa0e/checks

Thanks for the input.
As you mentioned I also don’t want to have the custom component code in my config repo.

I guess the best way forward is to help component developers add integrations support and not even having to add the component to the yaml configuration.

1 Like