Giter Site home page Giter Site logo

setup-p4's Introduction

Support

โš™๏ธ setup-p4

GitHub Action for running Perforce Helix Core P4 CLI commands.

The perforce/setup-p4 action is a JavaScript Action that sets up Perforce Helix Core P4 CLI in your GitHub Actions workflow, allowing you to easily create interactions between your repository and your Perforce server.

In addition, the Action includes the following features:

  • This Action supports all GitHub Hosted and Self-Hosted Runner Operating Systems
  • Defaults to latest version of P4 CLI but can be set to a specific version
  • All P4 CLI commands can be run from the Action
  • Adds p4 to PATH for easy access to P4 CLI
  • Optionally use GitHub Action Inputs to simplify setting up P4 CLI workflows
  • Connection details and credentials can be securely stored in the GitHub Action secrets

More features to come!

Usage

Quickstart

Start by creating GitHub Secrets for the following values. We will use these values later to connect to your Helix Core server.

  • P4PORT
  • P4USER
  • P4PASSWD

Example:

P4PORT="ssl:helixcore.example.com:1666"
P4USER="ci"
P4PASSWD="mysecurepassword"

Add the setup-p4 GitHub Action to your GitHub Workflow like so:

Define a job with environment variables that will be available for all steps:

jobs:
  quickstart:
    runs-on: ubuntu-latest
    name: quickstart

    env:
      P4PORT: ${{ secrets.P4PORT }}
      P4USER: ${{ secrets.P4USER }}
      P4PASSWD: ${{ secrets.P4PASSWD }}

Add a step that uses perforce/setup-p4@v1:

steps:
  - uses: perforce/setup-p4@v1
    with:
      command: login
      p4_version: 21.2

The above step will do the following:

  • based on p4_version, download, install, and add the P4 CLI to PATH. (Note: omitting this line will default to the latest version of the P4 CLI)
  • execute p4 login utilizing a GitHub Secret for the password with your

Now add a simple step that verifies authentication by running the p4 depots command:

steps:
  - uses: perforce/setup-p4@v1
    with:
      command: depots

Review the quickstart.yml for an example workflow that:

  • install p4 CLI
  • logs into Helix Core
  • creates a workspace (client)
  • pulls down assets from Helix Core

Inputs

Name Description Required Default
command p4 CLI command to execute yes
global_options p4 CLI global options that are supplied on the command line before the command no
arguments arguments specific to the P4 command being used no
working_directory directory to change into before running p4 command no .
spec spec content that is fed into p4 stdin to create/update resources no
p4_version version of p4 CLI to download and cache no 21.2

command

command supports all P4 CLI commands.

global_options

global_options supports all P4 global options.

Common global_options you may want to set would include

  • P4PORT by including -p ssl:helixcore.example.com:1666 in global_options
  • P4USER by including -u joe in global_options

arguments

arguments supports all P4 Command arguments. To find available arguments first find the command documentation and then look under the Options section.

working_directory

The Action will change directory to what is provided in working_directory. Note that the specified directory must exist.

spec

If spec is provided the contents of spec will be passed to the STDIN of the p4 command. In arguments include the option -i so that p4 reads from STDIN instead of opening your P4EDITOR. (See p4 client in quickstart.yml for an example.)

p4_version

p4_version defines the version of the p4 binary that will be downloaded and cached. p4_version should only be specified in a setup GitHub Action Step. In this step the it will check if the specified version is already present, if it is not it will be loaded, cached, and added to the $PATH. All subsequent steps will be able to use the p4 found in the $PATH.

See our CI workflows for examples.

Configuration

Environment Variables

The P4 CLI can utilize environment variables to get configuration and the same applies to p4 in GitHub Actions. GitHub Actions allows you to set environment variables at multiple levels:

  • Workflow
  • Job
  • Step

Note: Because workflows are visible to other users, you should use secrets to store sensitive information such as passwords.

- name: p4 sync
  uses: perforce/setup-p4@v1
  env:
  	P4CLIENT: sdp-dev-pipeline
  with:
    command: sync
    arguments: -f

Reference the quickstart.yml Workflow file in this repository for examples of setting environment variables at each level.

Secrets

All p4 commands will require valid authentication to your Helix Core server. Most Workflows will start with a p4 login like the following:

- name: p4 login
  uses: perforce/setup-p4@v1
  with:
    command: login
    global_options: '-p helixcore.example.com:1666 -u joe'
    env:
    	P4PASSWD: ${{ secrets.P4PASSWD }}

To use the above step your GitHub Repository will need to have a Secret named P4PASSWD and the contents will need to be the Helix Core password of the user you want to authenticate as.

You can name your GitHub Repository Secret anything you would like but the Action expects you to set the environment variable P4PASSWD to your user's Helix Core password.

Outputs

When using the provided helpers this action creates three outputs for all p4 commands: stdout, stderr, and exit_code. The following outputs are available for subsequent steps:

  • stdout - The STDOUT stream of the call to the p4 CLI.
  • stderr - The STDERR stream of the call to the p4 CLI.
  • exit_code - The exit code of the call to the p4 CLI.

Output Usage

The following is an example of how to use each of the outputs from this action:

- name: p4 depots
  id: depots
  uses: perforce/setup-p4@v1
  with:
    command: depots

- name: echo outputs from previous step
  run: |
    echo "this will print the outputs from the depots command in the previous step"
    echo "stdout was: ${{ steps.depots.outputs.stdout }}"   
    echo "stderr was: ${{ steps.depots.outputs.stderr }}"
    echo "exit code was: ${{ steps.depots.outputs.exit_code }}"

Versioning

We recommend pinning to the latest available major version:

- uses: perforce/setup-p4@v1

This action follows semantic versioning, but we're human and sometimes make mistakes. To prevent accidental breaking changes, you can also pin to a specific version:

- uses: perforce/[email protected]

However, you will not get automatic security updates or new features without explicitly updating your version number.

Helpers

After running the setup routine, subsequent steps in the same job can run arbitrary P4 CLI commands using the GitHub Actions run syntax. This allows most P4 CLI commands to work exactly like they do on your local command line. Take a look at setup-only.yml for an example of what this looks like.

Alternatively to running P4 CLI commands using the GitHub Actions run syntax you can use helpers that are provided by the setup-p4 action.

Benefits to using the helpers:

  • you don't have to worry about passing complex spec as stdin to the p4 command (example)
  • stdout, stderr, and exit_code are captured for you and stored as GitHub Outputs
  • Bad p4 commands, bad p4 arguments, bad p4 spec, and pipefail errors are all caught and will fail the GitHub Step to prevent false positives in your pipelines

Command Structure

  1. Installs the p4 CLI
  2. Builds up a p4 command based on your inputs. There are three scenarios that define how the command is built up
    1. p4 login
    2. STDIN required
    3. everything else

This is how the command gets built up:

COMMAND="p4 $GLOBAL_OPTIONS $COMMAND $ARGUMENTS"

p4 login

The p4 login command will read the user password from STDIN so $P4PASSWD gets echoed into $COMMAND.

echo "${P4PASSWD}" | ${COMMAND}

STDIN required

This command format is used whenever a p4 resource must be created or updated. The contents of your spec are passed to STDIN of p4 command.

echo "${SPEC}" | ${COMMAND}

Everything Else

${COMMAND}

Example GitHub Action Workflows

You can find some example workflows that use setup-p4 in the examples directory.

Name Description
Quickstart Basic example that performs a p4 login, creates a workspaces, and sync files down from Helix Core.
Setup Only This example performs the same steps as the Quickstart example but does not utilize any of the Action helper inputs
Action Outputs Echos the stdout, stderr, and exit code

Additionally here are example projects that use setup-p4

Detailed logs

To enable debug logging, create a GitHub Repository Secret named ACTIONS_STEP_DEBUG with the value true. See here for more information. Run your workflow again and review the new debug logging.

Limitations

Network Connectivity

GitHub Hosted Actions run in Azure so the list of Azure IPv4 addresses must be able to reach your Helix Core instance. To test if your Helix Core server is reachable from GitHub Hosted Actions create a workflow with the following content and run it:

on:
  workflow_dispatch:

name: Network Connectivity Test

jobs:

  network:
    runs-on: ubuntu-latest
    steps:
    - run: nc -vz ${your helix core public IP} 1666

If your Helix Core server is reachable you will see output like the following:

Run nc -vz public.perforce.com 1666
Connection to public.perforce.com 1666 port [tcp/*] succeeded!

and if it is not reachable you will get an error like the following:

Run nc -vz public.perforce.com 1666
nc: connect to public.perforce.com port 1666 (tcp) failed: Connection timed out
Error: Process completed with exit code 1.

Available Disk Space

GitHub Hosted Actions provide ~30GB of disk space to your workflow. Depending on your P4 Client Depot mapping you may run out of disk space. Your options are to update your Depot mapping to reduce what data is pulled down or switching to Self Hosted GitHub Actions.

Author Information

This module is maintained by the contributors listed on GitHub.

Development of this module is sponsored by Perforce.

Support

setup-p4 is a community supported project. Pull requests and issues are the responsibility of the project's moderator(s); this may be a vetted individual or team with members outside of the Perforce organization. All issues should be reported and managed via GitHub (not via Perforce's standard support process).

Code of Conduct

See CODE_OF_CONDUCT.md

License

See LICENSE

Contributor's Guide

Issues

Please create an issue for all bug or security vulnerability reports.

Discussions

To discuss feature requests, use cases, or to ask general questions please start a discussion.

Here are the steps for contributing:

  1. fork the project
  2. clone your fork to your workstation
  3. run npm ci to install all the dependencies
  4. run npm run build to package the action
  5. create a .actrc and act.secrets file for testing locally (examples below)
  6. run act --job unit , act --job smoke, and act --job integration before submitting a PR
    1. Note that the integration tests will require a running Helix Core server.
  7. commit changes and submit PR

act

act can be used to test GitHub Actions locally before having to commit any code.

.actrc

The .actrc can be used to provide default configuration to act. Example .actrc file to have act use the act.secrets file

--secret-file act.secrets

my.secrets

Create a my.secrets file (ignored via .gitignore file) that will allow the Action to authenticate to your Helix Core.

P4PASSWD=""
P4PORT=""
P4USER=""

setup-p4's People

Contributors

aboutte avatar dependabot[bot] avatar jase-perf avatar p4paul avatar ryanlitalien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

setup-p4's Issues

node.js v12 actions are deprecated and will be forced to v16 next week

https://github.blog/changelog/2023-05-04-github-actions-all-actions-will-run-on-node16-instead-of-node12/
As of May 18th, all actions will be forced to run run under node.js v16

Expected Behavior

No warnings when the action is used in a build.

Current Behavior

Warning when this action is used in a build:

Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: perforce/setup-p4@v1. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/.

Remove setup command

For the original js implementation I hijacked command: setup attribute to perform the installation, caching, etc of p4. It would be better to remove this and perform setup when p4_version is included.

Remove `setup` input

The setup input was used originally to ease some of the javascript but it is really unnecessary. Now that we are getting close to releasing and we are focusing on ease of use for the end user we should remove this input.

The new plan is to always run the setup routine and rely on caching to keep step execution fast. The different use cases that need to be supported are:

  1. if p4_version is not changed then the default version will get installed with the very first setup-p4 step
  2. if p4_version is changed in the first step we will install the requested version
  3. if p4_version is changed in a subsequent step we will download and install the secondary version
  4. if p4_version is left as default for step A, changed in step B, and again left as default in step C then in step C we should use the cached version in the step A
  smoke:
    name: smoke
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04]
    steps:
      - name: p4 info 21.2
        uses: ./
        with:
          command: -V
  smoke:
    name: smoke
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04]
    steps:
      - name: p4 info 20.1
        uses: ./
        with:
          p4_version: 20.1
          command: -V
  smoke:
    name: smoke
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04]
    steps:
      - name: p4 info 21.2
        uses: ./
        with:
          command: -V
      - name: p4 info 20.1
        uses: ./
        with:
          p4_version: 20.1
          command: -V
  smoke:
    name: smoke
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04]
    steps:
      - name: p4 info 21.2
        uses: ./
        with:
          command: -V
      - name: p4 info 20.1
        uses: ./
        with:
          p4_version: 20.1
          command: -V
      - name: p4 info 21.2
        uses: ./
        with:
          command: -V

Allow environment variables in `working_directory`

After dropping to the shell the expanded working directory on Linux was set to expanded working directory is set to: .%0A. I added .trim() to remove leading and trailing whitespace.

After dropping to the shell the expanded working directory on windwos was set to: 'working_directory' set to ".". I added .replace(/['"]+/g, '') to remove single and double quotes.

Add a timeout to all shelljs exec

Depending on what arguments are used it is possible p4 will expect user input forever. An example is the following:

      - name: p4 submit
        uses: setup-p4
        id: submit
        env:
          P4CLIENT: ci
        with:
          command: submit
          global_options: -I
          working_directory: "C:/Users/perforce/Perforce/ci/Game/"

Without -d being included in arguments p4 expects input from an interactive user.

TypeError: arguments.includes is not a function

After merging in #50 integration tests started failing with the following error:

(node:1684) UnhandledPromiseRejectionWarning: TypeError: arguments.includes is not a function
    at main (/home/runner/work/setup-p4-example-build-template/setup-p4-example-build-template/.github/actions/setup-p4/dist/index.js:13710:19)
    at setupP4 (/home/runner/work/setup-p4-example-build-template/setup-p4-example-build-template/.github/actions/setup-p4/dist/index.js:13646:3)
    at /home/runner/work/setup-p4-example-build-template/setup-p4-example-build-template/.github/actions/setup-p4/dist/index.js:13793:1
    at /home/runner/work/setup-p4-example-build-template/setup-p4-example-build-template/.github/actions/setup-p4/dist/index.js:13795:3
    at Object.<anonymous> (/home/runner/work/setup-p4-example-build-template/setup-p4-example-build-template/.github/actions/setup-p4/dist/index.js:13798:12)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:10[27](https://github.com/perforce/setup-p4-example-build-template/runs/5500668658?check_suite_focus=true#step:6:27):10)
    at Module.load (internal/modules/cjs/loader.js:863:[32](https://github.com/perforce/setup-p4-example-build-template/runs/5500668658?check_suite_focus=true#step:6:32))
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
(node:1684) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1684) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Here is an example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.