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

Print link to test-version zip in PR discussions #70

Merged
merged 17 commits into from
May 28, 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
13 changes: 11 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build

on: push
on:
push:
pull_request:

jobs:
build:
Expand Down Expand Up @@ -41,7 +43,14 @@ jobs:
mkdir tmp
unzip felt.${{ env.VERSION }}.zip -d tmp

- name: Save PR number to zips
run: |
cd tmp
echo ${{ github.event.number }} | tee pr_number
echo ${{ github.event.pull_request.head.sha }} | tee git_commit
echo ${{ github.event.number }}

- uses: actions/upload-artifact@v2
with:
name: felt_plugin.${{ env.VERSION }}.${{ env.SHA_SHORT }}
name: felt_plugin.${{ env.VERSION }}
path: tmp
104 changes: 104 additions & 0 deletions .github/workflows/build_artifact_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Write build artifact comments

on:
workflow_run:
workflows: ["Build"]
types:
- completed

permissions:
contents: read

jobs:
on-success:

permissions:
pull-requests: write

runs-on: ubuntu-latest
steps:
- name: Get source code
uses: actions/checkout@v4
with:
# To fetch tags
fetch-depth: 0

- name: 'Set plugin version environment variables'
run: |
TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "VERSION=$(echo ${TAG} | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')-alpha" >> $GITHUB_ENV
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: 'Download artifact'
id: download_artifact
uses: actions/github-script@v7
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == 'felt_plugin.${{ env.VERSION }}'
});
matchArtifacts.forEach((artifact) => {
});
if (matchArtifacts.length>0)
{
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifacts[0].id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/felt_plugin.${{ env.VERSION }}.zip`, Buffer.from(download.data));
core.setOutput('artifact_id', matchArtifacts[0].id);
}
else
{
core.setOutput('artifact_id', 0);
}

- name: 'Unzip artifact'
if: fromJSON(steps.download_artifact.outputs.artifact_id) > 0
run: |
unzip -n felt_plugin.${{ env.VERSION }}

- name: 'Post artifact download link as comment on PR'
if: fromJSON(steps.download_artifact.outputs.artifact_id) > 0
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fs = require('fs');
let issue_number = Number(fs.readFileSync('./pr_number'));
let git_sha = String(fs.readFileSync('./git_commit')).trim();
const prComments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const PREFIX = "## Plugin ready!";
let body = PREFIX + "\n\n" +
"A test version of this PR is available for testing [here](https://github.com/" + context.repo.owner + "/" + context.repo.repo + "/suites/" + context.payload.workflow_run.check_suite_id + "/artifacts/${{steps.download_artifact.outputs.artifact_id}}).";
body += "\n\n*(Built from commit " + git_sha + ")*";

const winBuildComment = prComments.data?.find(c => c.body.startsWith(PREFIX));
if (!!winBuildComment) {
// update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: winBuildComment.id,
body: body
});
} else {
// submit a new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: body
});
}
Loading