krlmlr / r-appveyor

Tools for using R with AppVeyor (https://appveyor.com)
132 stars 60 forks source link

Question about Environment Variables. #157

Closed chasemc closed 5 years ago

chasemc commented 5 years ago

ping @gaborcsardi In regards to: https://twitter.com/GaborCsardi/status/1146132795221315585

I am working on automating building/deploying shiny apps with appveyor.

Workflow:

Push to master -> should increment DESCRIPTION version -> should make GitHub release and build/attach binary to release (release name = DESCRIPTION version)

Kind of working:

https://github.com/chasemc/demoApp/blob/master/appveyor.yml

Originally I had been using %APPVEYOR_BUILD_VERSION% to bump the R package DESCRIPTION version. However, %APPVEYOR_BUILD_VERSION% increments on each build (e.g. pull requests, dev branches), which (while not necessarily wrong) causes the version number to seemingly 'skip' numbers and may confuse non-technical users of the software (would be nice to be 1.0.1, 1.0.2, 1.0.3, etc; not 1.0.1, 1.0.12, 1.0.14, etc).

https://github.com/chasemc/demoApp/blob/d22cb2dcdbfb36580adc39e38973082ba1f500b6/appveyor.yml#L38 https://github.com/chasemc/demoApp/blob/d22cb2dcdbfb36580adc39e38973082ba1f500b6/appveyor.yml#L103

Another route:

My next thought was to just use desc::desc_bump_version() and then read/use the new DESCRIPTION version to name the new release tag. However, while I can read environment variables into R, I haven't figured out how to create/or modify persistent environment variable from within R. Maybe it would just be easier to write it to a file and read it from powershell...

gaborcsardi commented 5 years ago

If you mean that you want to set an env var in an R session, and you want that to be set the same way in other, subsequent R sessions, that is not really possible, at least not via setting the env var within the R session.

You might be able to set the env var in the system config, though, e.g. try to use SETX: https://ss64.com/nt/setx.html You can call it from R via system2().

chasemc commented 5 years ago

I was trying to use setx , set, $env:myvar = myvalue and tried again today for some hours. For some reason I could never create a new variable, or even persistently modify an existing one from inside R (although it worked with a direct ps: call, so maybe it was my setup within R).

What I wound up doing was a little hacky: Created a new variable called appVersion

environment:
  global:
     appVersion: '0.0.0'

Then used the following to update the value:

  - Rscript -e "writeChar(as.character(desc::desc_get_version(list.files(pattern = 'DESCRIPTION', ignore.case = T, recursive = F))), 'version_temp.txt')" 
  - ps: $env:appVersion = Get-Content version_temp.txt 

Variable can then be accessed normally, e.g. tag: $(appVersion)

I have a couple order-of-operations things to fix still. Afterwards I'll link to my finished script so others can see.

chasemc commented 5 years ago

What I was trying to do if anyone runs across this: https://github.com/chasemc/demoApp/blob/master/appveyor.yml

Main goal: Use {electricShine} to build a shiny app into an Electron Windows app using appveyor.

On commits/push/pull to master, will automatically: