Build/Package a specific folder from GitHub

martinkerr's Avatar

martinkerr

21 Nov, 2018 09:36 AM

Hi,
Aftr the below discussion on Twitter:

Based on https://stackoverflow.com/a/4909267 . Replace 'user.repo' and 'folder1/folder2' with your values. Assume it is a GitHub, other Git VCS should work too. Will not work with Pull requests at least as is. Lets continue on https://help.appveyor.com/discussions/questions … where we can do a proper code snippets.

Try this 'init' stage, 'cmd' mode:
cd %APPVEYOR_BUILD_FOLDER%
git init
git config core.sparseCheckout true
git remote add -f origin git://github.com/user/repo.git > nul 2>&1
echo folder1/folder2/* > .git/info/sparse-checkout
git checkout -qf %APPVEYOR_REPO_COMMIT%

I cannot see that it has actually completed what i wanted it to do, it was successful but there are no real logs for me.

Thanks

  1. 1 Posted by martinkerr on 21 Nov, 2018 09:42 AM

    martinkerr's Avatar

    I am using the below YAML:

    version: 1.0.{build}
    build_script:
    - sh: >-
        cd %APPVEYOR_BUILD_FOLDER%

        git init

        git config core.sparseCheckout true

        git remote add -f origin https://github.com/User/Repo.git > nul 2>&1

        echo Folder/* > .git/info/sparse-checkout

        git checkout -qf %APPVEYOR_REPO_COMMIT%

  2. 2 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:02 PM

    Ilya Finkelshteyn's Avatar

    I am a little bit confused. It was proposed to run in cmd mode (assumed you run Windows build). If it is true, - sh: prefix is no-op and will be simple skipped on Windows. If you run Linux build, environment variable format is $variable, not %variable%

    In any case you can check results of this operation with tree -if --noreport . on Linux and dir /s or also tree on Windows.

  3. 3 Posted by martinkerr on 21 Nov, 2018 02:17 PM

    martinkerr's Avatar

    apologies, i selected the wrong option in the UI.

    I am now trying the script using the CMD function

    Thanks

  4. 4 Posted by martinkerr on 21 Nov, 2018 02:28 PM

    martinkerr's Avatar

    ok so it ran a little further, but it still clones the whole repo.

    Also i get the following error: Command exited with code 128

    Any further ideas?

    Thanks

  5. 5 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:30 PM

    Ilya Finkelshteyn's Avatar

    Do you use UI or YAML file? If you intend to use UI, do you have appveyor.yml in the repo?

  6. 6 Posted by martinkerr on 21 Nov, 2018 02:34 PM

    martinkerr's Avatar

    we usually use YAML file but i was just testing this quickly so was using the UI.

    There is no YAML in the repo

  7. 7 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:36 PM

    Ilya Finkelshteyn's Avatar

    OK, please share your config (Export YAML in UI) and link to the build.

  8. 8 Posted by martinkerr on 21 Nov, 2018 02:38 PM

    martinkerr's Avatar

    Build - https://ci.appveyor.com/project/ITSupport/client-branding
    YAML:

    version: 1.0.{build}
    build_script:
    - cmd: >-
        cd %APPVEYOR_BUILD_FOLDER%

        git init

        git config core.sparseCheckout true

        git remote add -f origin https://github.com/BenefexLtd/Client-Branding.git > nul 2>&1

        echo SkyscannerChina/* > .git/info/sparse-checkout

        git checkout -qf %APPVEYOR_REPO_COMMIT%

    after the one folder is cloned, all i want to do is package it up using octopack.exe and push to an Octopus Deploy server.

  9. 9 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:41 PM

    Ilya Finkelshteyn's Avatar

    Ah, I see now, you use https: and not git: prefix in git remote add command

  10. 10 Posted by martinkerr on 21 Nov, 2018 02:46 PM

    martinkerr's Avatar

    OK, i have changed and am trying to build again now

    ________________________________

  11. 11 Posted by martinkerr on 21 Nov, 2018 02:51 PM

    martinkerr's Avatar

    it is building now, but it still seems to be cloning the whole repo?

  12. 12 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:53 PM

    Ilya Finkelshteyn's Avatar

    Run dir /s after standard clone and after this (for example as install script), and compare the results.

  13. 13 Posted by martinkerr on 21 Nov, 2018 03:04 PM

    martinkerr's Avatar

    i may have been putting the scriptin the wrong place. It was in a build script, i have now changed it to an init scriptin the environment tab.

    Building again, so will see what happens

  14. 14 Posted by martinkerr on 21 Nov, 2018 03:05 PM

    martinkerr's Avatar

    failed with exit code 1

    i'm not sure where to put this script.

    You are welcome to change the config for me :)

    Thanks

  15. 15 Posted by Ilya Finkelshte... on 21 Nov, 2018 03:26 PM

    Ilya Finkelshteyn's Avatar

    I cannot change the config for you, unless you add me as a collaborator. But it is not needed. I checked what you sent one more time, and I see that you set this as a build script. It should be custom clone script. In UI you can find it in General setting tab.

  16. 16 Posted by martinkerr on 21 Nov, 2018 03:31 PM

    martinkerr's Avatar

    I've put into the clone script, but it still errors.

    Error code is 1

  17. 17 Posted by Ilya Finkelshte... on 21 Nov, 2018 03:37 PM

    Ilya Finkelshteyn's Avatar

    Last build I see is running as init and not a custom clone script

  18. 18 Posted by martinkerr on 21 Nov, 2018 03:38 PM

    martinkerr's Avatar

    build 1.0.9 was using clone script

  19. 19 Posted by Ilya Finkelshte... on 21 Nov, 2018 03:53 PM

    Ilya Finkelshteyn's Avatar

    I think it is because original sample was for public repo. Replace git://github.com/BenefexLtd/Client-Branding.git with git@github.com:BenefexLtd/Client-Branding.git and see if this works.

  20. 20 Posted by martinkerr on 21 Nov, 2018 11:02 PM

    martinkerr's Avatar

    Ok so the latest build worked, thank you.

    But where will the folder from the repo be stored within the build server now?

    And I assume I can use an after build script to run octopack and then push to my Octopus Deploy server?

    Also how do I only run this build script when I see a GitHub commit for this particular folder only within the repo?

    Thanks

    On 21 Nov 2018, at 15:53, Ilya Finkelshteyn <[email blocked]<mailto:[email blocked]>> wrote:

  21. 21 Posted by Ilya Finkelshte... on 22 Nov, 2018 12:40 AM

    Ilya Finkelshteyn's Avatar

    It should be within APPVEYOR_BUILD_FOLDER, which is default current directory for build. You can run CD and dir /s commands to understand the foolder structure. However as long as you do not change current folder, you can simple use relative path, which is in your case is simple that folder name. And you probably do not need to run octopack to just zip that folder, you can simple add folder to the artifacts with type of Octopus Package. In UI it is quite obvious, in YAML it can look like this:

    artifacts:
    - path: SkyscannerChina
      type: OctopusPackage
    
  22. 22 Posted by martinkerr on 22 Nov, 2018 09:42 AM

    martinkerr's Avatar

    Ok, i will try this.

    Then can i use the Octopus Deploy deploy steps to push to my octopus deploy server?

    Also, how can i only build if something in this particular folder has changed in GitHub?

    Thanks

    ________________________________

  23. 23 Posted by Ilya Finkelshte... on 22 Nov, 2018 12:25 PM

    Ilya Finkelshteyn's Avatar

    Yes, you can use Octopus Deploy steps after that.

    To trigger build if only specific folder changed, use this: https://www.appveyor.com/docs/how-to/filtering-commits/#commit-file...

  24. 24 Posted by martinkerr on 22 Nov, 2018 01:35 PM

    martinkerr's Avatar

    Where in the yml file would the only_commits part go?

    Thanks

    ________________________________

  25. 25 Posted by martinkerr on 22 Nov, 2018 02:22 PM

    martinkerr's Avatar

    Got it working, thanks!

    Another question though... when packaging artifacts can I exclude a file or file type?

    Thanks

    On 22 Nov 2018, at 13:35, Martin Kerr <[email blocked]<mailto:[email blocked]>> wrote:

    Where in the yml file would the only_commits part go?

    Thanks

    ________________________________

  26. 26 Posted by martinkerr on 22 Nov, 2018 04:50 PM

    martinkerr's Avatar

    Also, when using AppVeyor artifacts, how can a set a version number?

    Thanks

    ________________________________
    From: Martin Kerr
    Sent: 22 November 2018 14:21:46
    To: Ilya Finkelshteyn
    Subject: Re: Build/Package a specific folder from GitHub [Questions #30243]

    Got it working, thanks!

    Another question though... when packaging artifacts can I exclude a file or file type?

    Thanks

    On 22 Nov 2018, at 13:35, Martin Kerr <[email blocked]<mailto:[email blocked]>> wrote:

    Where in the yml file would the only_commits part go?

    Thanks

    ________________________________

  27. 27 Posted by Ilya Finkelshte... on 22 Nov, 2018 11:32 PM

    Ilya Finkelshteyn's Avatar

    You can delete files of specific type recursively from that folder before packaging. It can be part of build script for example. Quick search provides [this](https://blogs.technet.microsoft.com/heyscriptingguy/2006/10/23/how-...] and number of others which gives an idea of how to do that.

    Regarding artifact versioning. You can rename the folder to contain version and package it from the script. You can use
    APPVEYOR_BUILD_VERSION environment variable for that.

  28. Ilya Finkelshteyn closed this discussion on 23 Jan, 2019 09:05 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Sep, 2024 03:49 PM
26 Sep, 2024 09:02 AM
25 Sep, 2024 07:07 PM
24 Sep, 2024 08:39 PM
24 Sep, 2024 06:47 AM
20 Sep, 2024 05:50 PM