Skip to content

Commit

Permalink
Add structure and scripts for trigger validation / upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmillan committed Oct 26, 2023
1 parent 37757c4 commit a213e2f
Show file tree
Hide file tree
Showing 22 changed files with 1,810 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pull-request-commenter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Pull Request Commenter
on:
workflow_run:
workflows: ["Pull Request Validator"]
types:
- completed
jobs:
pull-request-commenter:
name: Commenter
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: |
cwd: util
- uses: actions/github-script@v6
with:
script: |
const download = require("./util/pull-request-validation-downloader.js");
await download({
github,
context,
core,
runID: ${{github.event.workflow_run.id}}
});
- run: unzip validation-results.zip
- uses: actions/github-script@v6
with:
script: |
const comment = require("./util/pull-request-commenter.js");
await comment({ github, context, core });
31 changes: 31 additions & 0 deletions .github/workflows/pull-request-validator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Pull Request Validator
on:
pull_request:
paths:
- "triggers/**"
branches: [main]
jobs:
pull-request-validator:
name: Validator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: |
cwd: util
- uses: actions/github-script@v6
with:
script: |
const validate = require("./util/pull-request-validator.js");
await validate({ github, context, core });
- uses: actions/upload-artifact@v3
if: always()
with:
name: validation-results.json
path: validation-results.json
retention-days: 1
89 changes: 89 additions & 0 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Upload
on:
push:
branches: main
jobs:
validate:
name: Validate
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: |
cwd: util
- uses: actions/github-script@v6
with:
script: |
const validateTriggers = require("./util/validate-triggers.js");
validateTriggers({ core });
icons:
needs: validate
name: Upload Icons
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: |
cwd: util
- uses: actions/github-script@v6
with:
script: |
const collectChangedIcons = require("./util/collect-changed-trigger-icons.js");
await collectChangedIcons({ github, context });
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.AWS_ROLE_ARN}}
aws-region: us-east-2
- run: aws s3 sync ${{runner.temp}}/icons s3://tuple-hooks-production/icons
archives:
needs: icons
name: Upload Archives and Metadata
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: |
cwd: util
- uses: actions/github-script@v6
with:
script: |
const archiveChangedTriggers = require("./util/archive-changed-triggers.js");
await archiveChangedTriggers({ github, context });
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.AWS_ROLE_ARN}}
aws-region: us-east-2
- run: aws s3 sync ${{runner.temp}}/archives s3://tuple-hooks-production/archives
- uses: actions/github-script@v6
with:
script: |
const uploadMetadata = require("./util/upload-metadata.js");
await uploadMetadata({
github,
context,
metadataDynamoDBTableName: "${{secrets.METADATA_DYNAMODB_TABLE_NAME}}",
contributorsDynamoDBTableName: "${{secrets.CONTRIBUTORS_DYNAMODB_TABLE_NAME}}"
});
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Tuple Community Triggers

This repository holds a bunch of [Tuple Triggers](https://tuple.app/triggers) that are accessible via the [Triggers
Directory](https://tuple.app/triggers/directory). You can learn more by reading the [Triggers
documentation](https://tuple.app/triggers/docs).

## Quick Start

You can quickly set up a new trigger using the generator provided in this repository:

```bash
scripts/generate-trigger
```

## Contributing

Please follow the guidance outlined [here](https://tuple.app/triggers/docs/submitting-your-trigger) to submit a new
trigger to this repository.
Binary file added scripts/assets/default-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions scripts/generate-trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

slugify() {
echo "$1" | iconv -t ascii//TRANSLIT | sed -E 's/[^a-zA-Z0-9]+/-/g' | tr A-Z a-z | sed -E 's/^-+|-+$//g'
}

to_lower() {
echo "$1" | tr 'A-Z' 'a-z'
}

SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
BASE_DIR="$SCRIPTPATH/.."
cd "$BASE_DIR"

echo "What would you like to name your trigger?"
read TRIGGER_NAME

echo "Please describe the functionality of your trigger?"
read TRIGGER_DESC

echo "What language will your trigger be written in?"
select TRIGGER_LANG in Bash Ruby JavaScript Python Applescript; do
break
done

echo "What platform will this trigger support?"
select TRIGGER_PLATFORM in macOS Linux Windows; do
break
done

NEW_TRIGGER_DIR="$BASE_DIR/triggers/$(slugify "$TRIGGER_NAME")"

mkdir "$NEW_TRIGGER_DIR"
cd "$NEW_TRIGGER_DIR"

mkdir assets
cp "$BASE_DIR/scripts/assets/default-icon.png" assets/icon.png

cat << EOF > README.md
# $TRIGGER_NAME
$TRIGGER_DESC
EOF

cat << EOF > config.json
{
"name": "$TRIGGER_NAME",
"description": "$TRIGGER_DESC",
"platforms": ["$(to_lower $TRIGGER_PLATFORM)"],
"language": "$(to_lower $TRIGGER_LANG)"
}
EOF

echo
echo "Your new trigger directory was generated at:"
echo "$(realpath $NEW_TRIGGER_DIR)"
Empty file added triggers/.keep
Empty file.
1 change: 1 addition & 0 deletions util/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
27 changes: 27 additions & 0 deletions util/archive-changed-triggers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const childProcess = require("child_process");
const { mkdirSync } = require("fs");
const { promisify } = require("util");
const extractChangedTriggers = require("./support/extract-changed-triggers.js");

const exec = promisify(childProcess.exec);
const outputDirectory = `${process.env.RUNNER_TEMP}/archives`;

async function archiveTrigger(trigger) {
const inputPath = `triggers/${trigger}`;
const outputPath = `${outputDirectory}/${trigger}.zip`;

console.log(`Archiving ${inputPath} to ${outputPath}`);

return exec(`cd ${inputPath} && zip -r ${outputPath} .`);
}

module.exports = async function archiveChangedTriggers({ github, context }) {
const changedTriggers = await extractChangedTriggers({
github,
context,
});

mkdirSync(outputDirectory, { recursive: true });

return Promise.all(changedTriggers.map(archiveTrigger));
};
22 changes: 22 additions & 0 deletions util/collect-changed-trigger-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { mkdirSync, copyFileSync } = require("fs");
const extractChangedTriggers = require("./support/extract-changed-triggers.js");
const outputDirectory = `${process.env.RUNNER_TEMP}/icons`;

module.exports = async function collectChangedTriggerIcons({
github,
context,
}) {
mkdirSync(outputDirectory, { recursive: true });

const changedTriggers = await extractChangedTriggers({
github,
context,
});

changedTriggers.forEach((trigger) => {
copyFileSync(
`triggers/${trigger}/assets/icon.png`,
`${outputDirectory}/${trigger}.png`
);
});
};
11 changes: 11 additions & 0 deletions util/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "tuple-community-triggers-utils",
"version": "0.0.1",
"private": true,
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.417.0",
"@aws-sdk/lib-dynamodb": "^3.417.0",
"ejs": "^3.1.9",
"zod": "^3.22.2"
}
}
Loading

0 comments on commit a213e2f

Please sign in to comment.