Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
feat: github action composite (#3)
Browse files Browse the repository at this point in the history
* feat: github action composite

* docs: update information about composite
  • Loading branch information
validcube authored Nov 20, 2023
1 parent 75e7abd commit 300e7fa
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 3 deletions.
10 changes: 8 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Thanks for consider contributing.

### `> Python`

> [!IMPORTANT]
> This guide assume that you already installed Python 3.10 or higher and pytest.
Expand All @@ -15,8 +17,12 @@ Developing the script:
> [!WARNING]
> Ruff is a linter made using Rust, it's super fast and doesn't output anything if everything passes, don't fall for it!
Here are some tip when contributing:
### `> GitHub Action Composite`

When contributing to GitHub Action Composite, please make sure that you follow [security hardening guide](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions).

## `> Nested JSON Postprocessor // Tips`

- All commits must follows the [Conventional Commits 1.0.0](https://www.conventionalcommits.org/en/v1.0.0/) guidelines.
- [Signing commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) are highly recommended.
- [Signing commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) are required.
- This repository follows slight variation of [Google's Python style](https://google.github.io/styleguide/pyguide.html) guide **but not strictly enforced**.
45 changes: 45 additions & 0 deletions README_ACTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# GitHub Action `> Nested JSON Postprocessor`

Remove null or empty keys, list and array from JSON files.

## `> Postprocessor // Usage`

Before you start, make sure that you have setup the supported version of Python in your workflow:

| Python version | Support status |
| -------------- | ---------------- |
| Upcoming | ⚙️ Best effort |
| 3.12 | ✅ Supported |
| 3.11 | ✅ Supported |
| 3.10 | ✅ Supported |
| 3.9 | ✅ Supported |
| 3.8 | ⚙️ Best effort |
| 3.7 | ⚙️ Best effort |
| =<3.6 | ❌ Not Supported |

```yml
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12
```
| Input | Required | Description |
| ---------------------- | ----------------------------------- | ------------------ |
| `source_dir` | ✅ Yes | Input directory |
| `destination_dir` | ❌ No (default to `source_dir`) | Output directory |
| `signing_key` | ❌ No | Signing key |
| `commit_message` | ❌ No (default to `JSON Cleanup`) | Commit message |
| `secrets.GITHUB_TOKEN` | ❌ No (default to GitHub's default) | GitHub's PAT token |

```yml
- name: Nested JSON Postprocessor
uses: ./.github/actions/python-action ???? # Soon:tm:
with:
source_dir: 'path/to/your/source/directory' # required, your input directory
destination_dir: 'path/to/your/destination/directory' # optional, default to source_dir
signing_key: 'your-signing-key' # optional, will skip signing if not provided
commit_message: 'your-custom-commit-message' # optional, default to "JSON Cleanup"
secrets:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # optional, default to GitHub's default
```
8 changes: 7 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ While this project may not be associated with any
security vulnerability ever:tm:, we'd still encourage everyone
to report them as soon as possible.

## Supported Versions
## Supported Program Versions

Right now, the latest version are only supported.

| Version | Supported |
| ------- | ------------------ |
| Latest | :white_check_mark: |

## Supported GitHub Action Composite Versions

| Version | Supported |
| ------- | ------------------ |
| Latest | :white_check_mark: |

## Supported Python Versions

| Version | Supported |
Expand Down
56 changes: 56 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Crowdin Nested JSON Postprocessor"
description: "Runs a Python script that remove empty string in JSON caused by Crowdin not respecting skip untranslated strings"

inputs:
source_dir:
description: "The source directory to copy"
required: true
destination_dir:
description: "The destination directory (optional)"
required: false
signing_key:
description: "The GPG key to sign commits (optional)"
required: false
commit_message:
description: "Commit message (optional)"
required: false
default: "JSON Cleanup"

runs:
using: "composite"
steps:
- name: Setup directories and copy files
run: |
mkdir -p input output
cp -r "${{ inputs.source_dir }}"/* input/
if [[ -n "${{ inputs.destination_dir }}" ]]; then
DESTINATION_DIR="${{ inputs.destination_dir }}"
else
DESTINATION_DIR=input
fi
shell: bash

- name: Run Python script
run: python3 main.py
shell: bash

- name: Copy output files
run: |
cp -r output/* "$DESTINATION_DIR/"
shell: bash

- name: Commit changes
run: |
echo "Committing changes..."
if [[ -n "${{ inputs.signing_key }}" ]]; then
git config --global user.signingkey "${{ inputs.signing_key }}"
git config --global commit.gpgsign true
COMMIT_OPTIONS="-S"
else
COMMIT_OPTIONS=""
fi
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
git add .
git commit $COMMIT_OPTIONS -m ${{ inputs.commit_message }}
git push
shell: bash

0 comments on commit 300e7fa

Please sign in to comment.