diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ab87be9..52968ab 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,3 +1,3 @@ { - "postCreateCommand": "chmod 777 .devcontainer/postCreateCommand.bash && .devcontainer/postCreateCommand.bash" -} \ No newline at end of file + "postCreateCommand": "chmod 777 .devcontainer/postCreateCommand.bash && .devcontainer/postCreateCommand.bash && source ~/.bashrc" +} diff --git a/.devcontainer/postCreateCommand.bash b/.devcontainer/postCreateCommand.bash index 0499fec..b0dbb37 100755 --- a/.devcontainer/postCreateCommand.bash +++ b/.devcontainer/postCreateCommand.bash @@ -6,4 +6,3 @@ curl https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3 tar -xjvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 echo "PATH=$PATH:/home/codespace/gcc-arm-none-eabi-10.3-2021.10/bin" >> ~/.bashrc popd -source ~/.bashrc \ No newline at end of file diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml new file mode 100644 index 0000000..f579cdd --- /dev/null +++ b/.github/workflows/pr-comment.yml @@ -0,0 +1,89 @@ +name: Add Template to Pull Request +on: + workflow_run: + workflows: ['Build Template'] + types: [completed] +jobs: + pr_comment: + # if Build Template was successful and ran on a branch that is currently the head in a pull request + if: github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + + permissions: + pull-requests: write + + steps: + - uses: actions/github-script@v6 + with: + # This snippet is public-domain, taken from + # https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml + script: | + async function upsertComment(owner, repo, issue_number, purpose,old_body, body) { + const {data: comments} = await github.rest.issues.listComments( + {owner, repo, issue_number}); + + const marker = `\r\n\r\n\r\n`; + + const old_marker = new RegExp(marker.replace("\r\n", "\r?\n")).exec(old_body)?.[0] ?? marker; + + body = old_body.split(old_marker)[0] + marker + body; + await github.request('PATCH /repos/{owner}/{repo}/pulls/{pull_number}', { + owner: owner, + repo: repo, + pull_number: issue_number, + body: body, + headers: { + 'X-GitHub-Api-Version': '2022-11-28' + } + }) + } + + const {owner, repo} = context.repo; + const run_id = ${{github.event.workflow_run.id}}; + + const pull_head_sha = '${{github.event.workflow_run.head_sha}}'; + + /** @type {{old_body: string}} */ + const {issue_number, old_body} = await (async () => { + const pulls = await github.rest.pulls.list({owner, repo}); + for await (const {data} of github.paginate.iterator(pulls)) { + for (const pull of data) { + if (pull.head.sha === pull_head_sha) { + return {issue_number: pull.number, old_body: pull.body}; + } + } + } + return {}; + })(); + if (issue_number) { + core.info(`Using pull request ${issue_number}`); + } else { + return core.error(`No matching pull request found`); + } + + let old_sha = /\<\!-- commit-sha: (?[a-z0-9]+) --\>/i.exec(old_body)?.groups?.sha + if (old_sha != undefined && pull_head_sha == old_sha) return core.error("Comment is already up-to-date!") + + const artifacts = await github.paginate( + github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id}); + if (!artifacts.length) { + return core.error(`No artifacts found, perhaps Build Template was skipped`); + } + const template = artifacts[0]; + + let body = `\n`; + body +=`## Download the template for this pull request: \n\n`; + body += `> [!NOTE] + > This is auto generated from [\`${{ github.workflow }}\`](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})\n`; + body += `- via manual download: [${template.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${template.id}.zip)\n`; + body += `- via PROS Integrated Terminal: \n \`\`\` + curl -o ${template.name}.zip https://nightly.link/${owner}/${repo}/actions/artifacts/${template.id}.zip; + pros c fetch ${template.name}.zip; + pros c apply ${template.name}; + rm ${template.name}.zip; + \`\`\``; + + core.info(`Review thread message body: \n${body}`); + + await upsertComment(owner, repo, issue_number, + "nightly-link", old_body, body); diff --git a/.github/workflows/pros-build.yml b/.github/workflows/pros-build.yml new file mode 100644 index 0000000..6dbaaac --- /dev/null +++ b/.github/workflows/pros-build.yml @@ -0,0 +1,18 @@ +name: Build Template + +on: + push: + branches: "**" + pull_request: + branches: "**" + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: LemLib/pros-build@e0f3251974c2f5b044b8e5d8665db7cfcb5dfad7 + with: + library-path: gamepad