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

Add ability to sync multiple collections and fix bugs #57

Merged
merged 12 commits into from
Apr 11, 2024
Merged
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
guru = {ref = "6c864e1", git = "https://github.com/guruhq/py-sdk.git"}
guru = {ref = "8b68816", git = "https://github.com/guruhq/py-sdk.git"}

[dev-packages]
types-beautifulsoup4 = "*"
Expand Down
136 changes: 27 additions & 109 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Sync card content from a Guru collection to a GitHub repository.

> [!NOTE]
> [!TIP]
> If you're looking to sync content from a GitHub repository to a Guru collection, check out [peckjon/github-to-guru](https://github.com/marketplace/actions/github-to-guru).

## Usage
Expand Down Expand Up @@ -51,8 +51,8 @@ jobs:
steps:
- uses: parkerbxyz/guru-to-github@v2
with:
guru_collection_id: '123ab'
collection_directory_path: 'collections'
guru-collection-ids: '123ab'
collection-directory-path: 'collections'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GURU_USER_EMAIL: ${{ vars.GURU_USER_EMAIL }}
Expand All @@ -61,7 +61,7 @@ jobs:

### Syncing more than one Guru Collection

You can sync more than one Collection using a matrix strategy:
You can sync more than one Collection by providing a comma-separated list of Collection IDs to the `guru-collection-ids` input.

```yaml
name: Guru to GitHub
Expand All @@ -75,31 +75,49 @@ on:
jobs:
guru-to-github:
runs-on: ubuntu-latest
strategy:
# Sync one Collection at a time to avoid conflicting changes to the metadata file
max-parallel: 1
matrix:
guru_collection_id: [123ab, 456cd]
env:
GURU_USER_EMAIL: ${{ vars.GURU_USER_EMAIL }}
GURU_USER_TOKEN: ${{ secrets.GURU_USER_TOKEN }}
steps:
# Get all Guru collections shared with the "All Members" group
- name: Get Guru collections
id: get-guru-collections
run: |
curl --request GET \
--url "https://api.getguru.com/api/v1/groups/$GURU_GROUP_ID/collections" \
--header 'accept: application/json' \
--user ${{ vars.GURU_USER_EMAIL }}:${{ secrets.GURU_USER_TOKEN }} \
--output collections.json
env:
GURU_GROUP_ID: "${{ vars.GURU_GROUP_ID }}"

- name: Create list
id: create-list
run: |
collection_ids=$(jq --compact-output '[.[].collection.id]' collections.json)
echo "collection_ids=$collection_ids" >> "$GITHUB_OUTPUT"
shell: bash

- uses: parkerbxyz/guru-to-github@v2
with:
guru_collection_id: ${{ matrix.guru_collection_id }}
collection_directory_path: 'collections'
guru-collection-ids: ${{ join(fromJson(steps.create-list.outputs.collection_ids)) }}
collection-directory-path: "collections"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GURU_USER_EMAIL: ${{ vars.GURU_USER_EMAIL }}
GURU_USER_TOKEN: ${{ secrets.GURU_USER_TOKEN }}
PUBLISH_UNVERIFIED_CARDS: ${{ true }}
```

Each Collection will exist as a subdirectory in the directory specified by `collection_directory_path`.

## Inputs

### `guru_collection_id`
### `guru-collection-ids`

**Required:** The ID(s) of the Guru Collection to sync.

**Required:** The ID of the Guru Collection to sync.
If syncing more than one Collection, provide a comma-separated list of Collection IDs.

### `collection_directory_path`
### `collection-directory-path`

**Required:** The path to the directory in the GitHub repository where the Guru Collection will be published.

Expand Down
20 changes: 12 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ branding:
inputs:
guru_collection_id:
description: "ID of the Guru Collection to sync"
required: true
deprecationMessage: "'guru_collection_id' is deprecated and will be removed in a future version. Use 'guru-collection-ids' instead."
guru-collection-ids:
description: "ID(s) of the Guru Collection(s) to sync"
collection_directory_path:
description: "Path to the directory where the Collection and metadata file should be synced to"
required: true
deprecationMessage: "'collection_directory_path' is deprecated and will be removed in a future version. Use 'collection-directory-path' instead."
collection-directory-path:
description: "Path to the directory where the Collection and metadata file should be synced to"

runs:
using: "composite"
Expand Down Expand Up @@ -42,31 +46,31 @@ runs:
# This allows us to keep the metadata file in the same directory as the collection(s)
- name: Create the collection directory if it does not exist
shell: bash
run: mkdir -p ${{ inputs.collection_directory_path }}
run: mkdir -p ${{ inputs.collection-directory-path || inputs.collection_directory_path }}
- run: git pull
if: ${{ !env.DRY_RUN }}
shell: bash
- name: Sync collection
working-directory: ${{ inputs.collection_directory_path }}
working-directory: ${{ inputs.collection-directory-path || inputs.collection_directory_path }}
shell: bash
run: pipenv run python ${{ github.action_path }}/github_publisher.py
env:
PIPENV_PIPFILE: ${{ github.action_path }}/Pipfile
GURU_COLLECTION_ID: ${{ inputs.guru_collection_id }}
COLLECTION_DIRECTORY_PATH: ${{ inputs.collection_directory_path }}
GURU_COLLECTION_IDS: ${{ inputs.guru-collection-ids || inputs.guru_collection_id }}
COLLECTION_DIRECTORY_PATH: ${{ inputs.collection-directory-path || inputs.collection_directory_path }}
- name: Pull changes from sync so we can update the metadata file
if: ${{ !env.DRY_RUN && !cancelled() }}
shell: bash
run: git pull
- uses: stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d # v5.0.0
if: ${{ !env.DRY_RUN && !cancelled() }}
with:
file_pattern: "${{ inputs.collection_directory_path }}/**/resources/*"
file_pattern: "${{ inputs.collection-directory-path || inputs.collection_directory_path }}/**/resources/*"
commit_message: "Update resources"
commit_author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
- uses: stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d # v5.0.0
if: ${{ !env.DRY_RUN && !cancelled() }}
with:
file_pattern: "${{ inputs.collection_directory_path }}/GitHubPublisher.json"
file_pattern: "${{ inputs.collection-directory-path || inputs.collection_directory_path }}/GitHubPublisher.json"
commit_message: "Update GitHubPublisher.json"
commit_author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
Loading