Generate capabilities #51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Generate capabilities" | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '13 05 */7 * *' | |
jobs: | |
build: | |
name: "Generate capabilities, presentation and translations" | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
contents: write | |
steps: | |
- name: "Checkout files" | |
uses: actions/checkout@v3 | |
- name: "Setup smartthings-cli" | |
run: | | |
wget "https://github.com/SmartThingsCommunity/smartthings-cli/releases/download/%40smartthings%2Fcli%401.8.2/smartthings-linux-x64.tar.gz" | |
tar -xvf smartthings-linux-x64.tar.gz | |
- name: "Use first secret" | |
run: | | |
SMARTTHINGS_TOKEN=$(echo ${{ secrets.SMARTTHINGS_TOKENS }} | head -n 1) | |
echo "SMARTTHINGS_TOKEN=$SMARTTHINGS_TOKEN" >> $GITHUB_ENV | |
- name: "Download smartthings capabilities" | |
run: ./smartthings capabilities -s -j --token "${{ env.SMARTTHINGS_TOKEN }}" -o capabilities.json | |
- name: "Process each capability" | |
run: | | |
cat capabilities.json | jq -c '.[]' | while read capability; do | |
id=$(echo $capability | jq -r '.id') | |
version=$(echo $capability | jq -r '.version') | |
echo "Processing $id version $version" | |
./smartthings capabilities $id -s -j --token ${{ env.SMARTTHINGS_TOKEN }} -o json/$id.json || true | |
./smartthings capabilities:presentation $id $version -j --token "${{ env.SMARTTHINGS_TOKEN }}" -o json/${id}Presentation.json || true | |
./smartthings capabilities:translations $id $version fr -j --token ${{ env.SMARTTHINGS_TOKEN }} -o json/$id.i18n.fr.json || true | |
./smartthings capabilities:translations $id $version en -j --token ${{ env.SMARTTHINGS_TOKEN }} -o json/$id.i18n.en.json || true | |
done | |
cat extra_capabilities_fix.json | jq -c '.[]' | while read capa; do | |
id=$(echo $capa | jq -r '.id') | |
version=$(echo $capa | jq -r '.version') | |
echo "Processing $id version $version" | |
./smartthings capabilities $id --token ${{ env.SMARTTHINGS_TOKEN }} -o json/$id.json | |
./smartthings capabilities:presentation $id $version -j --token ${{ env.SMARTTHINGS_TOKEN }} -o json/${id}Presentation.json || true | |
./smartthings capabilities:translations $id $version fr -j --token ${{ env.SMARTTHINGS_TOKEN }} -o json/$id.i18n.fr.json || true | |
./smartthings capabilities:translations $id $version en -j --token ${{ env.SMARTTHINGS_TOKEN }} -o json/$id.i18n.en.json || true | |
done | |
- name: "Print README.md" | |
run: | | |
PRINT="## SmartThings Capabilities\n" | |
PRINT+="#### Last Update: "$(date -I)"\n" | |
PRINT+="#### Edited by Flobul for Jeedom solution\n\n" | |
PRINT+="* [SmartThings Reference](https://smartthings.developer.samsung.com/docs/api-ref/capabilities.html)\n" | |
PRINT+="* [SmartThings API](https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#tag/capabilities)\n" | |
PRINT+="* [SmartThings CLI](https://github.com/SmartThingsCommunity/smartthings-cli)\n" | |
PRINT+="* [Create Personal Access Token](https://account.smartthings.com/tokens)\n" | |
PRINT+="* [Plugin Documentation](https://flobul-domotique.fr/documentation-du-plugin-smartthings-pour-jeedom/)\n" | |
PRINT+="* [Plugin Jeedom Market](https://market.jeedom.com/index.php?v=d&p=market_display&id=4099)\n" | |
PRINT+="| Capability | Version | Status | Capability Presentation | Translation i18n\n" | |
PRINT+="| ---- | ---- | ---- | ---- | ---- |\n\n" | |
ls json/*.json | grep -v i18n | grep -v Presentation.json | while read file; do | |
json=$(cat $file | sed 's/\\//g') | |
name=$(echo "$json" | jq -r '.name') || true | |
id=$(echo "$json" | jq -r '.id') || true | |
statuses=$(echo "$json" | jq -r '.status') || true | |
versions=$(echo "$json" | jq -r '.version') || true | |
presentation="" | |
i18n="" | |
if [ -f json/${id}Presentation.json ]; then | |
presentation="[json](./json/${id}Presentation.json)" | |
fi | |
if [ -f json/${id}.i18n.fr.json ]; then | |
i18n="[json](./json/${id}.i18n.fr.json)" | |
fi | |
PRINT+="| [$name](./json/$id.json) | $versions | $statuses | $presentation | $i18n |\n" | |
done | |
echo $PRINT > README.md | |
- name: "Create Pull Request" | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
add-paths: | | |
json/*.json | |
capabilities.json | |
branch: update | |
delete-branch: true | |
title: "Update capabilities" | |
body: "Automated capabilities update" | |
commit-message: "Auto update capabilities" |