dxw-wordpress-plugins / mirror-wordpress-plugins

Mirrors WordPress.org plugins to GitHub as versioned repos for use by Whippet
0 stars 0 forks source link

Add a dry run mode #11

Closed RobjS closed 8 months ago

RobjS commented 8 months ago

This adds the ability to run the command in dry-run mode by setting an env var of DRY_RUN=true.

Note that I've used a different way of accessing the env var here - ENV['var_name'] rather than ENV.fetch('var_name') as the latter will error if the variable doesn't exist, whereas the former will just return a default value of false.

How to test

  1. Copy the env.example file to .env and populate as follows:
    GITLAB_API_ENDPOINT=https://git.govpress.com/api/v4
    GITLAB_WORDPRESS_PLUGINS_GROUP_ID=71
    GH_ORG_NAME=dxw-wordpress-plugins
    DEFAULT_BRANCH_NAME=master
    GH_TEAM_ID=1234567 #this value will not be used so a random integer will do
    GH_ACCOUNT_USERNAME=dxw-govpress-tools
    GH_ACCOUNT_TOKEN=[the "mirror-gitlab-plugins" API token from the 1password entry for the github govpress tools service account]
    GITLAB_ACCOUNT_USERNAME=govpress-tools
    GITLAB_ACCOUNT_TOKEN=[the read-only API token from the 1password entry for the gitlab govpress tools service account]
    DRY_RUN=true
  2. Install act for testing GitHub actions locally: brew install act
  3. Run the action: act -j mirror-gitlab-plugins --secret-file .env. It should run successfully, outputting that it is in dry run mode, and what actions it would take, without performing those actions.