Skip to content

Commit c9255d5

Browse files
authored
Add "force" input (#80)
- Add "force" and "github-token" inputs - Add "installed" output
1 parent b20ded6 commit c9255d5

13 files changed

+374
-65
lines changed

.github/workflows/functional-tests.yml

Lines changed: 84 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,100 @@ name: Functional Tests
44
on: # yamllint disable-line rule:truthy
55
push:
66
branches:
7-
- "main"
7+
- main
88
pull_request:
9+
paths:
10+
- .github/workflows/functional-tests.yml
11+
- src/**
12+
- action.yml
13+
schedule:
14+
# Every Friday at 09:00 JST
15+
- cron: "0 0 * * 5"
16+
workflow_dispatch: {}
17+
18+
defaults:
19+
run:
20+
shell: sh
921

1022
jobs:
11-
functional_tests:
23+
get-versions:
24+
name: Get 3 latest versions
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 5
27+
outputs:
28+
versions: ${{ steps.prepare-list.outputs.versions }}
29+
steps:
30+
- name: Prepare list
31+
id: prepare-list
32+
env:
33+
RELEASES_AMOUNT: "3"
34+
TARGET_PIP_PACKAGE: "brainfucky"
35+
run: |
36+
versions=$(curl -s "https://pypi.org/pypi/${TARGET_PIP_PACKAGE}/json" \
37+
| jq -c -r --arg n "${RELEASES_AMOUNT}" '.releases | keys | .[-($n | tonumber):] | . += ["latest"]')
38+
echo "versions=${versions}" >> "$GITHUB_OUTPUT"
39+
run-script:
1240
name: Run script
41+
needs: [get-versions]
42+
runs-on: ${{ matrix.os }}-latest
1343
timeout-minutes: 5
1444
strategy:
1545
fail-fast: false
1646
matrix:
1747
os: ["ubuntu", "windows", "macos"]
18-
version: ["0.1.dev0", "0.1.dev1"]
19-
runs-on: ${{ matrix.os }}-latest
48+
version: ${{ fromJSON(needs.get-versions.outputs.versions) }}
2049
steps:
21-
- uses: actions/checkout@v4
22-
- uses: ./
50+
- name: Checkout ${{ github.repository }}
51+
uses: actions/checkout@v4
52+
- name: Setup brainfuck
53+
id: setup-brainfuck
54+
uses: ./
2355
with:
24-
version: ${{ matrix.version }}
25-
- name: Validate command (Linux, macOS)
26-
if: ${{ runner.os != 'Windows' }}
56+
version: "${{ matrix.version }}"
57+
- name: Test action completion
2758
run: |
28-
touch ./hello-world.bf
29-
echo "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.++" > ./hello-world.bf
30-
echo "+.------.--------.>>+.>++." >> ./hello-world.bf
31-
output=$(brainfucky --file ./hello-world.bf)
32-
rm ./hello-world.bf
33-
[[ "${output:32:12}" == "Hello World!" ]] || exit 1;
34-
shell: bash
35-
- name: Validate command (Windows)
36-
if: ${{ runner.os == 'Windows' }}
59+
test_equal() {
60+
if [ "${2}" != "${3}" ]; then
61+
echo "::error title=${1}::Expected: ${3}. Actual: ${2}."
62+
exit 1
63+
fi
64+
}
65+
test_equal "setup-brainfuck should be installed" \
66+
"${{ steps.setup-brainfuck.outputs.installed }}" \
67+
"true"
68+
test_equal "Wrong execution output" \
69+
"$(brainfucky --file ./hello-world.bf | sed -n '2p')" \
70+
"Hello World!"
71+
test-force:
72+
name: Test force
73+
runs-on: ubuntu-latest
74+
timeout-minutes: 5
75+
strategy:
76+
fail-fast: false
77+
matrix:
78+
force: ["true", "false"]
79+
steps:
80+
- name: Checkout ${{ github.repository }}
81+
uses: actions/checkout@v4
82+
- name: Setup brainfuck 1
83+
id: setup-brainfuck-1
84+
uses: ./
85+
- name: Setup brainfuck 2
86+
id: setup-brainfuck-2
87+
uses: ./
88+
with:
89+
force: ${{ matrix.force }}
90+
- name: Test action completion
3791
run: |
38-
New-Item -Path . -Name "hello-world.bf" -ItemType "file" -Value "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.++`n+.------.--------.>>+.>++."
39-
$Output = (brainfucky --file ./hello-world.bf) | Out-String
40-
Remove-Item hello-world.bf
41-
&{If($Output.Substring(33, 12) -ne 'Hello World!') {exit 1}}
42-
shell: pwsh
92+
test_equal() {
93+
if [ "${2}" != "${3}" ]; then
94+
echo "::error title=${1}::Expected: ${3}. Actual: ${2}."
95+
exit 1
96+
fi
97+
}
98+
test_equal "Wrong \"installed\" output from setup-brainfuck-1" \
99+
"${{ steps.setup-brainfuck-1.outputs.installed }}" \
100+
"true"
101+
test_equal "Wrong \"installed\" output from setup-brainfuck-2" \
102+
"${{ steps.setup-brainfuck-2.outputs.installed }}" \
103+
"${{ matrix.force }}"

.github/workflows/release.yml

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,6 @@ on: # yamllint disable-line rule:truthy
77
- "v*.*.*"
88

99
jobs:
10-
create-release:
11-
name: Create release
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v4
15-
with:
16-
fetch-depth: 0
17-
- name: Get changelog
18-
id: changelog
19-
uses: simbo/changes-since-last-release-action@v1
20-
- name: Create release
21-
uses: softprops/action-gh-release@v2
22-
with:
23-
tag_name: ${{ github.ref }}
24-
name: ${{ github.ref_name }}
25-
token: ${{ secrets.GITHUB_TOKEN }}
26-
body: |
27-
# Changelog
28-
29-
${{ steps.changelog.outputs.log }}
30-
draft: false
31-
prerelease: false
32-
- name: Bump tags
33-
uses: fischerscode/tagger@v0
34-
with:
35-
prefix: v
10+
github:
11+
name: GitHub
12+
uses: fabasoad/reusable-workflows/.github/workflows/wf-github-release.yml@main

.github/workflows/security.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Security
3+
4+
on: # yamllint disable-line rule:truthy
5+
pull_request: {}
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
sast:
12+
name: SAST
13+
permissions:
14+
contents: read
15+
security-events: write
16+
uses: fabasoad/reusable-workflows/.github/workflows/wf-security-sast.yml@main
17+
with:
18+
code-scanning: true
19+
sca: true

.github/workflows/sync-labels.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Labels
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches:
7+
- main
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
maintenance:
12+
name: Maintenance
13+
uses: fabasoad/reusable-workflows/.github/workflows/wf-sync-labels.yml@main

.github/workflows/update-license.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: License
3+
4+
on: # yamllint disable-line rule:truthy
5+
schedule:
6+
# Every January 1st at 14:00 JST
7+
- cron: "0 5 1 1 *"
8+
9+
jobs:
10+
maintenance:
11+
name: Maintenance
12+
uses: fabasoad/reusable-workflows/.github/workflows/wf-update-license.yml@main

.pre-commit-config.yaml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
---
22
default_install_hook_types: ["pre-commit", "pre-push"]
33
default_stages: ["pre-commit", "pre-push"]
4-
exclude: ^\.gitleaks\.toml$
54
minimum_pre_commit_version: 2.18.0
65
repos:
6+
# Linting
7+
- repo: local
8+
hooks:
9+
- id: prettier
10+
name: Prettier
11+
entry: prettier --write --ignore-unknown
12+
language: node
13+
types: [text]
14+
args: []
15+
files: ^(.*\.md|.*\.yaml|.*\.yml)$
16+
# https://github.com/prettier/prettier/releases
17+
additional_dependencies: ["[email protected]"]
18+
stages: ["pre-commit"]
719
# Security
820
- repo: https://github.com/Yelp/detect-secrets
921
rev: v1.5.0
@@ -13,12 +25,27 @@ repos:
1325
rev: v8.23.3
1426
hooks:
1527
- id: gitleaks
28+
- repo: https://github.com/fabasoad/pre-commit-grype
29+
rev: v0.6.2
30+
hooks:
31+
- id: grype-dir
32+
args:
33+
- --grype-args=--by-cve --fail-on=low
34+
- --hook-args=--log-level debug
35+
stages: ["pre-push"]
1636
# Markdown
1737
- repo: https://github.com/igorshubovych/markdownlint-cli
1838
rev: v0.44.0
1939
hooks:
2040
- id: markdownlint-fix
2141
stages: ["pre-commit"]
42+
# Shell
43+
- repo: https://github.com/openstack/bashate
44+
rev: 2.1.1
45+
hooks:
46+
- id: bashate
47+
args: ["-i", "E003,E006"]
48+
stages: ["pre-commit"]
2249
# Yaml
2350
- repo: https://github.com/adrienverge/yamllint
2451
rev: v1.35.1
@@ -33,15 +60,15 @@ repos:
3360
args: ["-pyflakes="]
3461
stages: ["pre-push"]
3562
# Other
36-
- repo: https://github.com/pre-commit/mirrors-prettier
37-
rev: v4.0.0-alpha.8
38-
hooks:
39-
- id: prettier
40-
stages: ["pre-commit"]
4163
- repo: https://github.com/pre-commit/pre-commit-hooks
4264
rev: v5.0.0
4365
hooks:
66+
- id: check-executables-have-shebangs
67+
stages: ["pre-commit"]
68+
- id: check-shebang-scripts-are-executable
69+
stages: ["pre-commit"]
4470
- id: check-merge-conflict
71+
stages: ["pre-commit"]
4572
- id: check-json
4673
stages: ["pre-push"]
4774
- id: detect-private-key

README.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,47 @@
44
![Releases](https://img.shields.io/github/v/release/fabasoad/setup-brainfuck-action?include_prereleases)
55
![functional-tests](https://github.com/fabasoad/setup-brainfuck-action/actions/workflows/functional-tests.yml/badge.svg)
66
![linting](https://github.com/fabasoad/setup-brainfuck-action/actions/workflows/linting.yml/badge.svg)
7+
![security](https://github.com/fabasoad/setup-brainfuck-action/actions/workflows/security.yml/badge.svg)
78

8-
This action installs one of the brainfuck interpreters called [brainfucky](https://pypi.org/project/brainfucky/).
9+
This action installs [brainfucky](https://pypi.org/project/brainfucky/) - one of
10+
the brainfuck interpreters.
11+
12+
## Supported OS
13+
14+
<!-- prettier-ignore-start -->
15+
| OS | |
16+
|---------|--------------------|
17+
| Windows | :white_check_mark: |
18+
| Linux | :white_check_mark: |
19+
| macOS | :white_check_mark: |
20+
<!-- prettier-ignore-end -->
921

1022
## Prerequisites
1123

12-
The following tools have to be installed for successful work of this GitHub action:
13-
[pip3](https://pip.pypa.io/en/stable/).
24+
None.
1425

1526
## Inputs
1627

28+
```yaml
29+
- uses: fabasoad/setup-brainfuck-action@v1
30+
with:
31+
# (Optional) brainfucky interpreter version. Defaults to the latest version.
32+
version: "0.1.dev1"
33+
# (Optional) If "false" skips installation if brainfucky is already installed.
34+
# If "true" installs brainfucky in any case. Defaults to "false".
35+
force: "false"
36+
# (Optional) GitHub token that is used to send requests to GitHub API such
37+
# as getting available python versions. Defaults to the token provided by
38+
# GitHub Actions environment.
39+
github-token: "${{ github.token }}"
40+
```
41+
42+
## Outputs
43+
1744
<!-- prettier-ignore-start -->
18-
| Name | Required | Description | Default | Possible values |
19-
|---------|----------|---------------------------------------------------------------------------------------------------|------------|------------------------|
20-
| version | No | Brainfucky library version that can be found [here](https://pypi.org/project/brainfucky/) version | `0.1.dev1` | `0.1.dev1`, `0.1.dev0` |
45+
| Name | Description | Example |
46+
|-----------|-----------------------------------------|---------|
47+
| installed | Whether brainfucky was installed or not | `true` |
2148
<!-- prettier-ignore-end -->
2249

2350
## Example usage

0 commit comments

Comments
 (0)