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

Merge main into feature/event-handler #5

Merged
merged 7 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"postCreateCommand": "chmod 777 .devcontainer/postCreateCommand.bash && .devcontainer/postCreateCommand.bash"
}
"postCreateCommand": "chmod 777 .devcontainer/postCreateCommand.bash && .devcontainer/postCreateCommand.bash && source ~/.bashrc"
}
1 change: 0 additions & 1 deletion .devcontainer/postCreateCommand.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
89 changes: 89 additions & 0 deletions .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
@@ -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<!-- DO NOT REMOVE!! -->\r\n<!-- bot: ${purpose} -->\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: (?<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 = `<!-- commit-sha: ${pull_head_sha} -->\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);
18 changes: 18 additions & 0 deletions .github/workflows/pros-build.yml
Original file line number Diff line number Diff line change
@@ -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
Loading