Skip to content

Commit

Permalink
Community survey
Browse files Browse the repository at this point in the history
  • Loading branch information
Survey bot committed Feb 4, 2025
0 parents commit 52ec1ea
Show file tree
Hide file tree
Showing 8 changed files with 2,113 additions and 0 deletions.
97 changes: 97 additions & 0 deletions .github/actions/append-survey-responses/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Append survey responses
inputs:
name:
description: 'Survey filename (without file extension, .json/.tsv)'
required: true
type: string
data:
description: 'JSON formatted string'
required: true
type: string
app_id:
description: ID of the GitHub App.
required: true
private_key:
description: Private key of the GitHub App (can be Base64 encoded).
required: true
runs:
using: composite
steps:
- name: Get current files
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Update files
uses: actions/github-script@v6
env:
FILENAME: ${{ inputs.name }}
DATA: ${{ inputs.data }}
with:
script: |
function getPreviousSurvey(file){
try{
const data = fs.readFileSync(file, 'utf-8');
return JSON.parse(data);
}catch(e){
console.error('File not found, fallback to empty array.\n', e);
return [];
}
}
const data = JSON.parse(process.env.DATA);
const fs = require('fs');
const filepath = 'surveys/'+process.env.FILENAME;
const surveys = getPreviousSurvey(filepath+'.json');
surveys.push(data);
surveys.sort((a,b) => a.timestamp.localeCompare(b.timestamp));
fs.writeFileSync(filepath+'.json', JSON.stringify(surveys), 'utf-8');
const tsvHeaders = ['timestamp'];
const tsv = [tsvHeaders];
surveys.forEach(survey => {
const row = [survey.timestamp];
tsv.push(row);
survey.queries.forEach(q => {
let headerIndex = tsvHeaders.findIndex(query => query === q.query);
if(headerIndex === -1){
headerIndex = tsvHeaders.length;
tsvHeaders.push(q.query);
}
row[headerIndex] = q.result;
});
});
tsv.forEach(row => {
while(row.length < tsvHeaders.length){
row.push('');
}
});
const tsvString = tsv.map(row => row.join('\t')).join('\n');
fs.writeFileSync(filepath+'.tsv', tsvString+'\n', 'utf-8');
- name: GitHub app JWT and installation access token generation
id: generate_token
uses: jamestrousdale/[email protected]
with:
app-id: ${{ inputs.app_id }}
private-key: ${{ inputs.private_key }}
- name: Set environment from action output
shell: bash
run: |
{
echo "GITHUB_APP_JWT=${{ steps.generate-github-app-tokens.outputs.jwt }}"
echo "GITHUB_APP_ACCESS_TOKEN=${{ steps.generate-github-app-tokens.outputs.access-token }}"
} >> ${GITHUB_ENV}
- name: Post results
shell: bash
run: |
git config user.name "Survey bot"
git config user.email 370152+survey-bot[app]@users.noreply.github.com
git config --add --bool push.autoSetupRemote true
git checkout --orphan latest_branch
git add -A
git commit -m "Community survey"
git branch -D ${{ github.ref_name }}
git branch -m ${{ github.ref_name }}
- name: Push to protected branch
uses: CasperWA/[email protected]
with:
token: ${{ steps.generate_token.outputs.access-token }}
branch: ${{ github.ref_name }}
force: true
174 changes: 174 additions & 0 deletions .github/workflows/community-survey.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
name: Community survey
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
post-usage-result:
needs: usage-survey
concurrency: post_result
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/append-survey-responses/
with:
name: usage
data: ${{ needs.usage-survey.outputs.data }}
app_id: ${{ secrets.APP_SURVEY_BOT_ID }}
private_key: ${{ secrets.APP_SURVEY_BOT_PEM_CONTENT }}
post-star-result:
needs: star-survey
concurrency: post_result
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/append-survey-responses/
with:
name: stars
data: ${{ needs.star-survey.outputs.data }}
app_id: ${{ secrets.APP_SURVEY_BOT_ID }}
private_key: ${{ secrets.APP_SURVEY_BOT_PEM_CONTENT }}
usage-survey:
runs-on: ubuntu-latest
outputs:
data: ${{ steps.get-query-results.outputs.result }}
steps:
- name: Get app token
id: get-app-token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.APP_PARTICIPANT_ID }}
private_key: ${{ secrets.APP_PARTICIPANT_PEM_CONTENT }}
- name: Get query results
id: get-query-results
uses: actions/github-script@v6
with:
github-token: ${{ steps.get-app-token.outputs.token }}
script: |
const sendQuery = async q => {
const url = 'https://api.github.com/search/repositories?q='+q+'&page=';
const repos = [];
let page = 1;
let data;
do{
const urlQuery = url+page++;
data = (await github.request(urlQuery)).data;
if(data.incomplete_results){
queries.push({
query: 'incomplete_results',
result: urlQuery
});
}
repos.push(...data.items);
}while(data.items.length);
return repos;
}
const timestamp = JSON.parse(JSON.stringify(new Date()));
const queries = [];
const excludedRepoOwners = repo => !['AI-Tournaments', 'ChrisAcrobat'].includes(repo.owner.login);
const response_total = await sendQuery('topic:AI-Tournaments');
queries.push({
query: 'AI-Tournaments_total',
result: response_total.length
});
queries.push({
query: 'AI-Tournaments_totalExclusive',
result: response_total.filter(excludedRepoOwners).length
});
const response_participants = await sendQuery('topic:AI-Tournaments+topic:AI-Tournaments-Participant');
queries.push({
query: 'participants',
result: response_participants.filter(repo => !repo.topics.includes('ai-tournaments-retired')).length
});
queries.push({
query: 'participantsExclusive',
result: response_participants.filter(excludedRepoOwners).filter(repo => !repo.topics.includes('ai-tournaments-retired')).length
});
queries.push({
query: 'retiredParticipants',
result: response_participants.filter(repo => repo.topics.includes('ai-tournaments-retired')).length
});
const response_arenas = await sendQuery('topic:AI-Tournaments+topic:AI-Tournaments-Arena-v1');
queries.push({
query: 'arenas',
result: response_arenas.length
});
queries.push({
query: 'arenasExclusive',
result: response_arenas.filter(excludedRepoOwners).length
});
const response_replays = await sendQuery('topic:AI-Tournaments+topic:AI-Tournaments-Replay');
queries.push({
query: 'replays',
result: response_replays.length
});
queries.push({
query: 'replaysExclusive',
result: response_replays.filter(excludedRepoOwners).length
});
const response_interfaces = await sendQuery('topic:AI-Tournaments-Interface');
queries.push({
query: 'interfaces',
result: response_interfaces.length
});
queries.push({
query: 'interfacesExclusive',
result: response_interfaces.filter(excludedRepoOwners).length
});
return {timestamp, queries};
star-survey:
runs-on: ubuntu-latest
outputs:
data: ${{ steps.get-query-results.outputs.result }}
steps:
- name: Get app token
id: get-app-token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.APP_PARTICIPANT_ID }}
private_key: ${{ secrets.APP_PARTICIPANT_PEM_CONTENT }}
- name: Get query results
id: get-query-results
uses: actions/github-script@v6
with:
github-token: ${{ steps.get-app-token.outputs.token }}
script: |
const sendQuery = async q => {
const url = 'https://api.github.com/search/repositories?q='+q+'&page=';
const repos = [];
let page = 1;
let data;
do{
const urlQuery = url+page++;
data = (await github.request(urlQuery)).data;
if(data.incomplete_results){
queries.push({
query: 'incomplete_results',
result: urlQuery
});
}
repos.push(...data.items);
}while(data.items.length);
return repos;
}
const timestamp = JSON.parse(JSON.stringify(new Date()));
const queries = [];
const response_stars = await sendQuery('user:AI-Tournaments');
let totalStars = 0;
response_stars.filter(r => !r.private).forEach(r => {
queries.push({
query: 'stars_'+r.name,
result: r.stargazers_count
});
totalStars += r.stargazers_count;
});
queries.push({
query: 'stars_total',
result: totalStars
});
return {timestamp, queries};
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 AI-Tournaments

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Automated community surveys
1 change: 1 addition & 0 deletions surveys/stars.json

Large diffs are not rendered by default.

Loading

0 comments on commit 52ec1ea

Please sign in to comment.