Can I save the Percy token to a file? - cypress

I'm learning Percy and Cypress right now. I'm still working locally, without a CI. Since I have more than 1 project, I have to manually change the Percy token (using export PERCY_TOKEN=myToken in Terminal) every time I switch between projects. Can I avoid this by specifying the token in a file? If so, which one?

Assuming you're using macOS or Linux, if you have a bashrc or zshrc file, you should be able to export the PERCY_TOKEN as a variable in that file.
export PERCY_TOKEN=myToken
After saving your .*rc file, you will need to either restart your terminal, or simply source the updated file.
source ~/path/to/.*rc

Related

How to rename .env variables in package.json?

What I have
I have multiple projects using Percy for Cypress where I set the PERCY_TOKEN env variable inside the .env file. The token is different for each project. In the CI I set different env variables for each project, but locally I have to do it in the .env file. Because of this, I have to edit the .env file whenever I change between projects.
Goal
I would like to set them in the .env file this way:
PROJECT_A_PERCY_TOKEN=tokenhash1
PROJECT_B_PERCY_TOKEN=tokenhash2
So later I could rename these variables to PERCY_TOKEN, eliminating the need to constantly change the .env file.
What I tried
I'm trying to do this inside the package.json file's scripts property. Unfortunately echo $PROJECT_A_PERCY_TOKEN prints nothing. I know that I could create a shell/python/js script that parses the .env file, then passes the value back or calls npm run directly but I would like to do this without an external script.
Problem
It appears to me that I can't access the env variables inside package.json. Is there a way to rename the variable only using the npm script?
tl;dr
If the package you try to configure has the ability to do configuration via a JavaScript file, you can add the renaming at the beginning of it:
process.env.PERCY_TOKEN = process.env.CYPRESS_PERCY_SALESFORCE_TOKEN;
Explanation
While this isn't the solution I was looking for, it is a workaround for this specific use case. Percy supports JavaScript config files so I migrated my YAML config file, then I logged process.env and the .env file's variables were there, so I just need to copy the correct one. This might work for other packages that support JavaScript config files (or some alternative kind of hook/preloader where custom code can be placed), but if they don't, then the question is still unanswered.

How to handle support files during Homebrew Formula update

I'm following the Scripts with Support Files answer from here https://stackoverflow.com/a/46479538/4771016 which works great but running into a problem during the update of my script.
If not found, my script creates an .env file for the users to pass some variables in the same directory as the .sh file lives: /home/linuxbrew/.linuxbrew/Cellar/myscript/1.0.2/libexec/.env the problem is that upon releasing a new version, the .env file won't be in the new directory i.e. /home/linuxbrew/.linuxbrew/Cellar/myscript/1.0.3/libexec/ and thus will be recreated losing the modifications.
Any ideas for keeping that .env file during updates or an acceptable design pattern for my use case? I was thinking about keeping the .env file outside that directory somewhere, but I don't know the Homebrew directory structure well enough to store it in the right place.

Run a command before and after running an interactive command

I have a command say intr-cmd which opens an interactive console for web framework. But I need to run command cmd-a before and cmd-b after running the intr-cmd manually. These commands change some files for intr-cmd to run.
How can I code this in Bash such that I only have to run intr-cmd and these commands are run before and after it.
Edit:
Some explanation
intr-cmd opens an interactive console but it first reads a file of currently installed plugins to load them. But there is a plugin which is installed on production but is not working on the local environment and it is not necessary for my work. but the plugins file is committed into the git. so I have to comment on the plugin then run the intr-cmd and then uncomment that line in the file.
I want to automate this step so that it does not accidentally get committed to the git.
You can create a function intr-cmd, which replaces the general intr-cmd command, as explained here.
I should like like:
intr-cmd()
{
cmd-a
/path/intr-cmd
cmd-b
}
(Obviously you need to fill in the right path.)
I tried to flag your question as a duplicate, but as the link refers to another StackExchange forum, this wasn't allowed, hence this answer.
In your case, instead of changing intr-cmd each time you need it, you could create a git branch (possibly in a specific clone of your git repo) for your testing environment with a modified version of intr-cmd, and/or a modified version of the plugin list.

Run Script with xCode Server Bot

I am running a on-commit Bot to build, analyze, unit tes and archive my App and it works perfectly.
I have a script (*.sh) in my porject that I want to run at the end of a success analysis. I am using xcode 7.3 now and i tried the following:
In the trigger section call ./myscript.sh, but the bot could not find it.
I tried to add $SCROOT, still no luck
I tried to copy the script to bin but since the bot runs under that __xcbuild user it did not see it, and I do not want to mess with adding permission to /bin and /usr/bin
All I want is to run a script against the code the that the bot just pulled on success.
The source used by Xcode CI will be under a cache folder stored in an environment variable called:
$XCS_SOURCE_DIR
Your file should be somewhere under that path

Script to sync P4 code with a label

I'm writing a script to sync P4 code with an existing label using command "p4 sync #labelname".
I have a network folder mapped as (S:) where i have the workspace "check".
The issue i'm facing is when i issue the sync command, it is creating a duplicate directory as "SUVHTV~2"
in S: and updating the changes instead of updating in S:/check
Note: Workspace "check" is created using Perforce and Root is provided as (S:/check)
This seems like your environment variable for P4CLIENT is not set properly. Please explicitly set this variable in your script.
I am assuming you have cygwin/mks toolkit or some other unix-shell-on-windows software.
Try adding this line before you make the call to p4 sync command and see if it helps.
export P4CLIENT='check'

Resources