Tutorial / Montana Mendy – Solutions Engineer

Sometimes you want a Perforce instance up and running as fast as possible. You can find bash scripts online, but are they tailored to you?

Things you’ll need:

  • ChatGPT account
  • OpenAI API Key
  • Basic knowledge of the CLI
  • Rust basics

This assumes:

  • You don’t have Perforce installed
  • You don’t have Helix Swarm installed
  • Blank slate as it pertains to depots/streams

When managing tons of Perforce instances, you can utilize ChatGPT to make a suite of bash scripts to help you out and do tasks a lot quicker, for example, fetching P4Proxy and giving me default environment variables:

image 2

In the use-case above, I’m using aichat, which you can find here: https://github.com/sigoden/aichat. Follow the instructions and install it from there. We have our P4Proxy bash script, now what if we wanted to have a regular Perforce setup, nothing special, just things like:

#!/bin/bash

set -e

wget http://cdist2.perforce.com/perforce/r21.1/bin.linux26x86_64/p4 -O /usr/local/bin/p4

chmod +x /usr/local/bin/p4

echo "P4USER=<username>" >> ~/.bashrc

echo "P4PORT=<server_address>:<port>" >> ~/.bashrc

p4 -c $P4CLIENT set P4USER=<username>

p4 -c $P4CLIENT set P4PORT=<server_address>:<port

This will install the Perforce in the binary /usr/local/bin/p4 and label under it 'p4`. You should now be able to set environment variables.

Environment Variables

In this case we are using Assembla + Perforce, so our environment variables look like this:

P4PORT=ssl:perforce-us-east.assembla.com:1667

P4HOST=spacetest/p4-test

P4CLIENT=perforce

P4USER=MontanaMendy

P4_ssl:perforce-us-east.assembla.com:1667_CHARSET=auto

Populating the mainline stream

In the example below, I want to populate my mainline stream with a depot called mendy I’d run the following:

p4 depot -t stream //depot/mendy

Now let’s setup the the typemap:

cat typemap.txt | p4 typemap -i

We’re now going to create the mendy stream:

p4 stream -t mainline $mendy

Submitting your files

You’ll need to make sure you are in the correct workspace by running p4 workspace. Check your changelist status by running p4 changes to ensure that all the files you made changes to are included in your changelist.

Next run p4 submit and review the changelist description that pops up in the text editor.

Now in the changelist description, include a brief summary of the changes you made and any relevant comments or details. Be sure to follow any specific requirements set by your team or organization. This would be similar to a git commit message. 

Save and close the changelist description file, then exit the submit command by pressing Ctrl+C (Windows) or Command+C (Mac/Unix). After the changelist is submitted, you will receive a notification indicating the changelist number along with any messages or errors that may have occurred during the submission process.

You’ll now have files in the mendy stream. Now run p4 sync.

Script to list streams

Let’s create a bash script to list my current streams, well let’s ask aichat to do that:

image 4

Workspace

To check you’re in the correct workspace run:

p4 where /depot/main/...

You should see something like this:

image 5

Script to change workspaces

Change your P4CLIENT to whatever you want then run this:

#!/bin/bash

set -e

p4 client -S //depot/main -o | p4 client -i

To make sure you’re in the correct workspace, just use grep and have it search the p4enviro file:

p4 info | grep 'User name'

p4 info | grep 'Client name'

You should get the results you were looking for and it should look similar to this:

image 6

Helix Swarm

Back to asking aichat things, let’s ask it to build us a bash script to install Helix Swarm:

image 3

Now as you can see Helix Swarm is installed, you can start to see how much time this could save in aggregate. Then run swarmctl start to start Helix Swarm, and then if you want to test it locally, you can do this via: http://localhost:8080/swarm.

Conclusion

You now have just set up Perforce and saved a lot of aggregate time using the aichat tool that uses ChatGPT. Version 2 of this blog post will be coming out soon, with more automation and more of a seamless Perforce setup using aichat.

As always, if you have any questions, any questions at all, please email me at montana@assembla.com.

Happy Perforcing & Assemblaing!

Montana Mendy – Solutions Engineer for Assembla