Skip to content

Commit

Permalink
Add "Test source" workflow (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabasoad authored Jan 14, 2024
1 parent 61e96b2 commit eec5d6e
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 483 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Security
on: # yamllint disable-line rule:truthy
push:
branches:
- 'main'
- main
pull_request:

defaults:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sync-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on: # yamllint disable-line rule:truthy
- main
paths:
- .github/labels.yml
- .github/workflows/sync-labels.yml
workflow_dispatch:

jobs:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
---
name: Functional Tests
name: Test providers

on:
pull_request:
paths:
- .github/workflows/test-providers.yml
- dist/**
- src/**
- action.yml
push:
branches:
- "main"
pull_request:
- main

defaults:
run:
shell: sh

jobs:
translate:
test-providers:
name: ${{ matrix.provider }}
timeout-minutes: 5
runs-on: ubuntu-latest
Expand Down Expand Up @@ -61,4 +70,3 @@ jobs:
run: |
echo "'${{ matrix.source }}' has been translated to '${{ steps.result.outputs.text }}'"
[ "${{ steps.result.outputs.text }}" = "${{ matrix.expected }}" ] || exit 1;
shell: sh
54 changes: 54 additions & 0 deletions .github/workflows/test-source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: Test source

on:
pull_request:
paths:
- .github/workflows/test-source.yml
- dist/**
- src/**
- action.yml
push:
branches:
- main

defaults:
run:
shell: sh

jobs:
test-source:
name: Source as ${{ matrix.source }}
timeout-minutes: 5
runs-on: ubuntu-latest
env:
TEXT: "Love"
EXPECTED: "Любов"
strategy:
matrix:
source: ["file", "text"]
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Prepare source
id: params
run: |
if [ "${{ matrix.source }}" = "file" ]; then
source="source.txt"
echo "${TEXT}" > "${source}"
else
source="${TEXT}"
fi
echo "source=${source}" >> "$GITHUB_OUTPUT"
- name: Translate
uses: ./
id: translate
with:
provider: "deepl"
lang: "en-uk"
source: "${{ steps.params.outputs.source }}"
api_key: "${{ secrets.DEEPL_API_KEY }}"
- name: Validate translated text
run: |
echo "'${TEXT}' has been translated to '${{ steps.translate.outputs.text }}'"
[ "${{ steps.translate.outputs.text }}" = "${EXPECTED}" ] || exit 1;
8 changes: 6 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
name: Unit Tests

on:
pull_request:
paths:
- dist/**
- src/**
- jest.config.json
push:
branches:
- 'main'
pull_request:
- main

defaults:
run:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/fabasoad/translation-action?include_prereleases)
![unit-tests](https://github.com/fabasoad/translation-action/actions/workflows/unit-tests.yml/badge.svg)
![functional-tests](https://github.com/fabasoad/translation-action/actions/workflows/functional-tests.yml/badge.svg)
![test-providers](https://github.com/fabasoad/translation-action/actions/workflows/test-providers.yml/badge.svg)
![test-source](https://github.com/fabasoad/translation-action/actions/workflows/test-source.yml/badge.svg)
![security](https://github.com/fabasoad/translation-action/actions/workflows/security.yml/badge.svg)
![linting](https://github.com/fabasoad/translation-action/actions/workflows/linting.yml/badge.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/84bb3beceb9503272bc9/maintainability)](https://codeclimate.com/github/fabasoad/translation-action/maintainability)
Expand Down
29 changes: 17 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
---
name: 'Translation Action'
name: "Translation Action"
author: Yevhen Fabizhevskyi
description: 'This action translates any text to any language supported by chosen provider.'
description: "This action translates any text to any language supported by chosen provider."
branding:
icon: users
color: green
inputs:
source:
description: 'Text or path to the file for translation.'
description: |
Text or path to the file (absolute or relative to $GITHUB_WORKSPACE) for
translation.
required: true
provider:
description: 'Provider identifier.'
description: "Provider identifier."
required: true
api_key:
description: 'API key that should be used for chosen provider.'
description: "API key that should be used for chosen provider."
required: false
default: ''
default: ""
api_additional_parameter:
description: 'Additional parameter for the API. eg the region for Microsoft: canadacentral.'
description: |
Additional parameter for the API. eg the region for Microsoft: canadacentral.
required: false
default: ''
default: ""
lang:
description: 'The translation direction. Should be one of the option proposed by chosen provider.'
description: |
The translation direction. Should be one of the option proposed by chosen
provider.
required: true
outputs:
text:
description: 'Translated text.'
description: "Translated text."
runs:
using: 'node20'
main: 'dist/index.js'
using: "node20"
main: "dist/index.js"
Loading

0 comments on commit eec5d6e

Please sign in to comment.