Giter Site home page Giter Site logo

cwtools / cwtools-action Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 5.0 193 KB

Run CWTools on your Clausewitz mod PDXScript code in parallel to your builds thanks to GitHub Actions.

License: MIT License

Dockerfile 0.58% Ruby 69.06% Shell 30.36%
cwtools paradox-interactive paradoxgame modding modding-tools action actions hearts-of-iron-4 heartsofiron4 hearts-of-iron-iv

cwtools-action's Introduction

CWTools Action

Run CWTools on your Clausewitz mod PDXScript code in parallel to your builds.

If CWTools finds errors, warnings or suggestions in the mod code then they will be output.

It will also insert them as inline feedback into your PRs ("Files changed" tab):

pr_example

Setup

GitHub: Can't use GitHub? Click here for GitLab installation instructions .

In most cases, no setup is required beyond adding the following workflow yml file to your project (.github/workflows folder) and setting the correct game. See below for advanced configuration and an explanation of the tools used.

The following games require no further setup:

  • HOI4
  • Stellaris

Example workflow yml

name: CWTools CI

on: [pull_request, push] # other events may work but are not supported

jobs:
  cwtools_job:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1 # required
    - uses: cwtools/[email protected]
      with:
        game: hoi4
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required, secret is automatically set by github

This action will create a new job called "CWTools", which will be used to annotate your code. Its success or failure state depends on the CWTools output.

The full output.json log is saved to $GITHUB_WORKSPACE, and can be recovered with actions/upload-artifact.

    - uses: cwtools/[email protected]
      with:
        game: hoi4
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    - name: Upload artifact
      if: always() # so even if the check fails, the log is uploaded
      uses: actions/[email protected]
      with:
        name: cwtools_output
        path: output.json

Configuration

game (required)

What game to use. Allowed values: hoi4, ck2, eu4, ir, stellaris, vic2.

    - uses: cwtools/[email protected]
      with:
        game: hoi4
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

modPath (optional)

Path to the mod folder in $GITHUB_WORKSPACE (root of repository). (Default: "" - root of repository itself)

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        modPath: "mod_folder"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cache (optional)

Path to the full cache file (cwb.bz2) in $GITHUB_WORKSPACE (root of repository). Use an empty string to use metadata from cwtools/cwtools-cache-files (Default: use metadata)

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        cache: "cache/hoi4.cwb.bz2"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

locLanguages (optional)

Which languages to check localisation for, space separated, lowercase (eg. english spanish russian). Note: May be different from game to game. (Default: english)

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        locLanguages: "english spanish russian"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

vanillaMode (optional)

Whether to not use cache, and instead treat the project as a vanilla game installation folder - if you are a modder, you probably should not be using this. If True, cache input will be ignored (Default: False, set to anything other than 0 or blank for True)

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        vanillaMode: "1"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

rules (optional)

What rules repository to use (Default: https://github.com/cwtools/cwtools-$INPUT_GAME-config.git)

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        rules: "https://github.com/Yard1/cwtools-hoi4-config.git"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

rulesRef (optional)

What ref on rules repo to checkout (Default: master)

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        rulesRef: "1.0.0"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

changedFilesOnly (optional)

By default will only annotate changed files in a push or a pull request. In order to annotate all files set changedFilesOnly input to "0".

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        changedFilesOnly: "0"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

suppressedOffenceCategories (optional)

You can choose to suppress annotations with chosen CWTools offence category IDs (CW###) per GitHub severity type (failure, warning, notice).

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        suppressedOffenceCategories: '{"failure":["CW110", "CW210"], "warning":[], "notice":[]}' # will suppress CW110 and CW210 category failures, but will show those for warnings and notices
      env:
        default: ${{ secrets.GITHUB_TOKEN }}

suppressedFiles (optional)

You can choose to suppress annotations completely in certain files. Use paths from root of repository, make sure to have no trailing whitespace. Globbing is not supported.

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        suppressedFiles: '["common/scripted_effects/my_effects.txt", "events/EventFile.txt"]' # will completely suppress any annotations in those two files
      env:
        default: ${{ secrets.GITHUB_TOKEN }}

CWToolsCLIVersion (optional)

Which CWTools.CLI version to use (Default: latest stable).

    - uses: cwtools/[email protected]
      with:
        game: hoi4
        CWToolsCLIVersion: '0.0.7'
      env:
        default: ${{ secrets.GITHUB_TOKEN }}

GitLab

Due to limitations with GitLab, this currently only works for merge requests to master

Running this action on GitLab is a bit more involved, requiring the creation of a bot account. It is also limited to providing comments on pull requests as shown here:

GitLab example

Setting up the bot account

  1. Create a new GitLab account for this "bot" and give it "Reporter" access to your project.
  2. Log into the account, browse to the Personal Access Token page and generate a PAT with "api" scope. Make a note of the token.
  3. Log back into your primary account.
  4. Browse to your Project and go to "Settings", "CI / CD", and open the section "Variables".
  5. Create a variable called "REVIEWDOG_GITLAB_API_TOKEN". Put the PAT generated above as the Value, then set it as "Masked" but not Protected.
  6. Press "Save variables".

Please note: This PAT gives access to all projects the bot can access. If somebody gets access to your pipeline logs, it's possible (although not likely) that they could access the token.

Configuring gitlab-ci

  1. In the root of your project create a file called .gitlab-ci.yml
  2. Copy the contents of the example file GitLab_CWToolsCI.yml, found in /examples, into it.
  3. Configure the variables if desired (see above).
  4. Create a merge request and check it works!

GitLab self-hosted

If you're running your own instance of GitLab, you'll need to set the following two variables in addition to those in the default template:

 - GITLAB_API: "https://example.gitlab.com/api/v4"
 - REVIEWDOG_INSECURE_SKIP_VERIFY: true

How this works

CWTools is a .NET library that provides features to analyse and manipulate the scripting language used in Paradox Development Studio's games (PDXScript). This is mainly used in a VS Code extension, cwtools-vscode. CWTools also provides a CLI tool CWTools.CLI to allow automated anaylsis, which is what this action relies on.

This action relies on two things:

  1. A set of valiation rules written for the game your mod is for
  2. A cache file containing key information from vanilla files

Validation rules

The validation rules are taken from the master branch of the public repository for the game, e.g. https://github.com/cwtools/cwtools-hoi4-config. The settings rules and rulesRef can be used to specify an alternative repo, or to stay on an old version of the rules.

Vanilla cache file

In order to validate correctly, CWTools requires certain data from the vanilla game files such as defined localisation, variables, etc. There are two formats of cache file:

Metadata only

The metadata format contains a limited set of information from vanilla, enough to run the main validator. For convenience CWTools automatically generates these metadata cache files for the latest public rules and latest version of each game. These are found here and are used by default in this action (please note that not all games may be supported yet).

Full

The full format contains a more details, processed, version of the vanilla script files. This is required in order to provide accurate validation taking load order and file overrides into account. This is the same format used by cwtools-vscode. We do not provide these files, however this action can be configured to use them.

Credits

Created by Antoni Baum (Yard1).

Using tboby/cwtools.

Based on gimenete/rubocop-action by Alberto Gimeno.

cwtools-action's People

Contributors

tboby avatar yard1 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

cwtools-action's Issues

`create_github_check': Forbidden (RuntimeError) in Vic2ToHoI4

Tool 'cwtools.cli' (version '0.0.15') was successfully installed.
Cloning into '/src/cwtools-hoi4-config'...
Using metadata cache from 'cwtools/cwtools-cache-files'...
If git fails here, it is most likely because the selected game (hoi4) is not yet supported in the 'cwtools/cwtools-cache-files'. In that case, use CWTools.CLI to generate a full cache of selected game and set it with the cache parameter. Consult README for more information.
Cloning into 'cwtools-cache-files'...
renamed 'cwtools-cache-files/hoi4.cwv.bz2' -> './hoi4.cwv.bz2'
CWTOOLS CHECK
CI ENVIROMENT: github
Is pull request...
Annotating only changed files...
"{\"message\":\"Resource not accessible by integration\",\"documentation_url\":\"https://docs.github.com/rest/reference/checks#create-a-check-run\"}"
/action/lib/cwtools.rb:138:in `create_github_check': Forbidden (RuntimeError)
	from /action/lib/cwtools.rb:303:in `run_github'
	from /action/lib/cwtools.rb:326:in `run'
	from /action/lib/cwtools.rb:333:in `<main>'

Full log:
https://github.com/ParadoxGameConverters/Vic2ToHoI4/pull/972/checks?check_run_id=2493040090

Here's the workflow:

name: CWTools CI

on: [pull_request, push] # other events may work but are not supported

jobs:
  cwtools_job:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1 # required
    - uses: cwtools/[email protected]
      with:
        game: hoi4
        modPath: "Vic2ToHoI4/Data_Files/blankMod/output"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

What might be causing this?

Actions can't access updated code, limited to code released 3 years ago

Apologies, I'm kind of new to the whole actions thing but I couldn't find any way to reference the updated code.

Setting up the action using the given installation instructions just produced errors because I'm using the tools for validating ck3 mods and that wasn't added until after the initial release. Forking and releasing a version in my own repositories allowed me to set up the action and it worked flawlessly.

Investigate whether it's possible to use git fetch for GitLab.

Currently using GIT_STRATEGY: fetch (the default) results in cwtools-action failing on GitLab. This is because reviewdog needs both the source and target branches of the merge request to be present for the git diff it does.

Git clone seems to solve this, and is more reliable. However, for large mods it can be quite slow to clone even just the last 50 commits, so it would be preferable to use git fetch.

This issue tracks any progress towards that. Please emote if this is something that affects you!

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.