Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🚀 upgrade gherkin support #1

Merged
merged 11 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Build and Deploy

on:
push:
branches: [main]
pull_request:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

permissions:
contents: write
pages: write
id-token: write

jobs:
check:
runs-on: ubuntu-latest
outputs:
status: ${{ steps.check.outputs.status }}
steps:
- uses: actions/checkout@v3
- id: changes
uses: dorny/paths-filter@v2
with:
filters: |
production:
- 'src/**'
- 'pom.xml'
- id: check
name: Check production files changes
run: |
status="skip"
if [ "${{ steps.changes.outputs.production }}" == "true" ]; then
status="deploy"
fi
echo "status=$status" >> $GITHUB_OUTPUT

publish:
runs-on: ubuntu-latest
needs: check
if: "needs.check.outputs.status == 'deploy' && !contains(github.event.head_commit.message, 'ci skip')"
steps:
- uses: actions/checkout@v3
# with:
# ssh-key: ${{ secrets.ACTION_BOT_SECRET_KEY }}

- name: Set up java
uses: actions/setup-java@v3
with:
java-version: 17
distribution: adopt
cache: maven
server-id: ossrh
server-username: OSS_SONATYPE_USERNAME
server-password: OSS_SONATYPE_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Create maven release version
if: ${{ github.event_name == 'push' }}
run: mvn -f pom.xml -q build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion} versions:commit

- name: Deploy
run: mvn --batch-mode --update-snapshots deploy -P release
env:
OSS_SONATYPE_USERNAME: ${{ secrets.OSS_SONATYPE_USERNAME }}
OSS_SONATYPE_PASSWORD: ${{ secrets.OSS_SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

- uses: actions/upload-artifact@v3
with:
name: my-artifact
path: |
target/asciidoctor-gherkin-extension-*.jar
target/asciidoctor-gherkin-extension-*.pom
retention-days: 1

- name: Create and commit next dev version
if: ${{ github.event_name == 'push' }}
run: mvn -f pom.xml -q build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}-SNAPSHOT versions:commit

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Post release - ci skip
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.classpath
.project
.settings/
target/
target
.vscode
*.iml
.idea
2 changes: 0 additions & 2 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)
101 changes: 101 additions & 0 deletions DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Github actions

TODO:

- [x] migrer vers la librairie https://mvnrepository.com/artifact/io.cucumber/gherkin/27.0.0
- [x] gérer 'Rule'
- [x] gérer 'Background' sans 'name'
- [x] ~~ITs~~
- [x] TU
- [ ] github action to maven deploy
- [ ] README

# Publication maven centrale en local

A titre d'exemple, voici les commande permettant de chiffrer et publier les artefacts.

## 1. Signature du jar

https://central.sonatype.org/publish/requirements/gpg/#gpg-signed-components

Generate keys:

```bash
gpg --gen-key
```

```bash
gpg --list-signatures --keyid-format 0xshort

pub rsa3072/0xtututututu 2023-03-28 [SC] [expire : 2025-03-27]
6666666666666666666666666666666666666666
uid [ ultime ] Julien Boz <[email protected]>
sig 3 0xtututututu 2023-03-28 Julien Boz <[email protected]>
sub rsa3072/0xBBBBBBBB 2023-03-28 [E] [expire : 2025-03-27]
sig 0xtututututu 2023-03-28 Julien Boz <[email protected]>
```

Optional but best practice, distribute public key on the internet to allow people to verify files:

```bash
gpg --keyserver keyserver.ubuntu.com --send-keys 6666666666666666666666666666666666666666
```

Optional, Export keys:

```bash
gpg --output .release/pubring.gpg --armor --export 6666666666666666666666666666666666666666
gpg --output .release/secring.gpg --armor --export-secret-key 6666666666666666666666666666666666666666
```

Test jar signatures:

```bash
export GPG_KEYNAME=0xtututututu
export GPG_PASSPHRASE=gpg-passphrase-defined

mvn clean verify -P release
```

## 2. Upload maven centrale

Documentation is here: https://central.sonatype.org/publish/manage-user/

Generate an access token on this page https://oss.sonatype.org/#profile;User%20Token (some time the web interface bugs and you have to reconnect yourself)

Create settings.xml :

```
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>ossrh</id>
<username>${env.SONATYPE_USERNAME}</username>
<password>${env.SONATYPE_PASSWORD}</password>
</server>
</servers>
</settings>
```

```bash
export SONATYPE_USERNAME=toto
export SONATYPE_PASSWORD=titi

mvn clean deploy -P release --settings .release/settings.xml
```

## 3. Lost secret ?

Use this in github action :

```yaml
- name: Set env as secret
env:
MY_VAL: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
run: |
import os
for q in (os.getenv("MY_VAL")):
print(q)
shell: python
```
4 changes: 4 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=============================================================================
= NOTICE file corresponding to section 4d of the Apache License Version 2.0 =
=============================================================================
This product includes software developed by FocusIT (http://www.ifocusit.ch/).
103 changes: 31 additions & 72 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
= asciidoctor-gherkin-extension
:github-url: https://github.com/domgold/asciidoctor-gherkin-extension/blob/master
:github-url: https://github.com/jboz/asciidoctor-gherkin-extension/tree/feature/upgrade_gherkin_support
http://asciidoctor.org[Asciidoctor] extension to format gherkin feature files in asciidoc files.

You can use this extension to include your gherkin feature files in asciidoc in the form of sections, paragraphs, lists and tables.

The conversion is based on a simple, customizable erb template.
The conversion is based on a simple and customizable erb template.

Thanks to https://github.com/domgold/asciidoctor-gherkin-extension for the work.

This project is up to date with the last gherkin specification and use the last version of the https://github.com/cucumber/gherkin library.
Take a look at https://cucumber.io/docs/gherkin/reference/ to see the full supported syntax.

== Usage

Expand All @@ -26,9 +31,9 @@ Feature: A simple feature

can be included via the gherkin block macro :

....
----
gherkin::./simple.feature[]
....
----

and gets rendered into a 3rd level section with subsections :

Expand All @@ -40,12 +45,10 @@ This is the feature description.

==== Background

[.step-list]
* *Given* a simple background step.

==== Scenario title

[.step-list]
* *Given* a simple scenario step
* *When* I render the asciidoctor content to html
* *Then* my feature gets nicely formatted in html.
Expand All @@ -61,43 +64,6 @@ gherkin::./simple.feature[]

Or just create your own template.

See the integration tests for a {github-url}/src/it/asciidoctor-maven-with-gherkin-it/pom.xml[complete maven example].

=== Formatting tables

You can add some asciidoctor formatting to tables, e.g. column widths, header style, etc.

For example, the following gherkin table

----
Given a complex background step with table with header
#cols=".<2,.^5,^.>3",options="header"
#cells=h,h,h
| Header Cell 1 | Header Cell 2 | Header Cell 3 |
#cells=,m,
| Cell 1 Row 1 | Cell 2 Row 1 monospace | Cell 3 Row 1 |
| Cell 1 Row 2 with *bold* | Cell 2 Row 2 | Cell 3 Row 2 |
----

renders as asciidoctor equivalent :

----
[.step-list]
* *Given* a complex background step with table with header
+
[cols=".<2,.^5,^.>3",options="header"]
|====
h| Header Cell 1 h| Header Cell 2 h| Header Cell 3
| Cell 1 Row 1 m| Cell 2 Row 1 monospace | Cell 3 Row 1
| Cell 1 Row 2 with *bold* | Cell 2 Row 2 | Cell 3 Row 2
|====

----

If the first comment of the first row starts with "cols=", then the content of the comment gets placed between brackets right before the table.

Row comments starting with "cells=" get split on "," and become cell formatters.

== Custom templates

You can use the `template` attribute to specify a custom `erb` template.
Expand All @@ -108,47 +74,40 @@ Here is an example of a custom template rendering a table with one row per scena

.mytemplate.erb
----
.<%= feature['name'] %>
|====
<%if feature.key?('scenarios') %><% feature['scenarios'].each do |scenario| %>| <%= scenario['name'] %>
<% end %>
<% else %>
| Nothing to show.
<% end %>
|====
:tip-caption: 💡
ifdef::env-github[]
:tip-caption: :bulb:
endif::[]

[TIP]
====
Implemented feature: https://linkToMyFeature[<%= feature.getName() %>]
====
----

assuming you place this template in the same directory as your asciidoc file, the following asciidoc content

----
gherkin::./simple.feature[template=mytemplate.erb]

//or this : (template is the first positional attribute)

gherkin::./simple.feature[mytemplate.erb]
----

would render like

.My feature title
|====
| Scenario title1
| Scenario title2
|====

== Character Encoding
:tip-caption: 💡
ifdef::env-github[]
:tip-caption: :bulb:
endif::[]

You can use attributes to define the encoding for reading the template file and the feature file.
[TIP]
====
Implemented feature: https://linkToMyFeature[My feature title]
====

You can define these attributes either in the block macro or at the document level.
== Options

template-encoding::
Used to read the custom template file if specified.
encoding::
Used to read the feature file.


.Defining feature encoding
You can define attribut(s) in the asciddoc way :
----
gherkin::./simple.feature[encoding=UTF-8]
gherkin::./simple.feature[attribut1=value1,attribut2=value2]
----

To see the list of available attributes and their default values open file src/main/java/ch/ifocusit/asciidoctor/gherkin/GherkinAsciidocBuilder.java
Loading