diff --git a/.github/ISSUE_TEMPLATE/update-collection.yml b/.github/ISSUE_TEMPLATE/update-collection.yml new file mode 100644 index 00000000..9cc42308 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/update-collection.yml @@ -0,0 +1,49 @@ +name: Want to add a dev container collection? +description: Dev container collection contribution template +labels: [collection] + +title: "Add a collection to the index" + +body: + +- type: input + id: name + attributes: + label: Collection name + validations: + required: true + +- type: input + id: maintainer + attributes: + label: Maintainer name + validations: + required: true + +- type: input + id: contact + attributes: + label: Maintainer contact link (i.e. repo issues link, email) + validations: + required: true + +- type: input + id: repository + attributes: + label: Repository URL + validations: + required: true + +- type: input + id: ociReference + attributes: + label: OCI Reference + validations: + required: true + +- type: checkboxes + attributes: + label: I acknowledge that this collection provides new functionality, distinct from the existing collections part of this index + options: + - label: Confirm + required: true \ No newline at end of file diff --git a/.github/workflows/collection.yml b/.github/workflows/collection.yml new file mode 100644 index 00000000..8f49f35d --- /dev/null +++ b/.github/workflows/collection.yml @@ -0,0 +1,46 @@ +name: Update collection +on: + issue_comment: + types: [created] + branches: + - gh-pages +jobs: + update_collection: + runs-on: ubuntu-latest + if: contains(github.event.comment.body, '#sign-off') && (github.event.comment.user.login == 'bamurtaugh' || contains(github.event.comment.user.login, 'devcontainers/maintainers')) + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-node@v2 + with: + node-version: '16' + + - name: Install js-yaml + run: npm install js-yaml + + - run: sudo apt-get install jq + + - uses: stefanbuck/github-issue-praser@v3 + id: issue-parser + with: + template-path: .github/ISSUE_TEMPLATE/update-collection.yml + + - run: | + cat <collection.json + ${{ steps.issue-parser.outputs.jsonString }} + EOF + + - run: node _data/update-collection.js + + - name: Commit changes + shell: bash + run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" && \ + git config --global user.name "github-actions[bot]" && \ + git add _data/collection-index.yml && \ + git commit -m 'Add collection' && \ + git push + + - uses: peter-evans/close-issue@v1 + with: + comment: Thanks so much for your contribution! Your collection is now part of our community index. Check out the collection-index.yml and containers.dev/collections. \ No newline at end of file diff --git a/_data/update-collection.js b/_data/update-collection.js new file mode 100644 index 00000000..faea9cbf --- /dev/null +++ b/_data/update-collection.js @@ -0,0 +1,38 @@ +const fs = require('fs'); +const yaml = require('js-yaml'); +const eventPayload = require(process.env.GITHUB_EVENT_PATH); + +const issueBodyLines = eventPayload.issue.body.split(/\r?\n/); + +let name, maintainer, contact, repository, ociReference; + +issueBodyLines.forEach((line, index) => { + const trimmedLine = line.trim().toLowerCase(); + switch (trimmedLine) { + case '### collection name': + name = issueBodyLines[index + 2]; + break; + case '### maintainer name': + maintainer = issueBodyLines[index + 2]; + break; + case '### maintainer contact link (i.e. repo issues link, email)': + contact = issueBodyLines[index + 2]; + break; + case '### repository url': + repository = issueBodyLines[index + 2]; + break; + case '### oci reference': + ociReference = issueBodyLines[index + 2]; + break; + } +}); + +const content = +`\n- name: ${name} + maintainer: ${maintainer} + contact: ${contact} + repository: ${repository} + ociReference: ${ociReference} +`; + +fs.appendFileSync(`${process.env.GITHUB_WORKSPACE}/_data/collection-index.yml`, content); \ No newline at end of file