You've already forked library-registry
mirror of
https://github.com/arduino/library-registry.git
synced 2025-07-29 14:01:15 +03:00
Get PR diff in dedicated job
This isolates the PR branch checkout from the request parsing process.
This commit is contained in:
52
.github/workflows/manage-prs.yml
vendored
52
.github/workflows/manage-prs.yml
vendored
@ -33,10 +33,48 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Dummy step to make job valid
|
- name: Dummy step to make job valid
|
||||||
run: ""
|
run: ""
|
||||||
|
diff:
|
||||||
|
needs:
|
||||||
|
- enabled
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
artifact: ${{ steps.configuration.outputs.artifact }}
|
||||||
|
path: ${{ steps.configuration.outputs.path }}
|
||||||
|
filename: ${{ steps.configuration.outputs.filename }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set configuration outputs
|
||||||
|
id: configuration
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=artifact::diff"
|
||||||
|
echo "::set-output name=path::${{ runner.temp }}"
|
||||||
|
echo "::set-output name=filename::diff.txt"
|
||||||
|
|
||||||
|
- name: Checkout local repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Checkout PR branch
|
||||||
|
run: |
|
||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally
|
||||||
|
# It's necessary to reference both pull_request.number and issue.number because only one of the two are defined depending on whether the workflow is triggered by PR or comment event.
|
||||||
|
git fetch origin pull/${{ github.event.pull_request.number }}${{ github.event.issue.number }}/head:pr-branch
|
||||||
|
git checkout pr-branch
|
||||||
|
|
||||||
|
- name: Generate diff file
|
||||||
|
run: |
|
||||||
|
git diff --unified=0 --ignore-blank-lines --ignore-space-at-eol --output="${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}" ${{ github.sha }}
|
||||||
|
|
||||||
|
- name: Upload diff file to workflow artifact
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
path: ${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}
|
||||||
|
name: ${{ steps.configuration.outputs.artifact }}
|
||||||
|
|
||||||
parse:
|
parse:
|
||||||
needs:
|
needs:
|
||||||
- enabled
|
- enabled
|
||||||
|
- diff
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
@ -62,23 +100,21 @@ jobs:
|
|||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
version: 3.x
|
version: 3.x
|
||||||
|
|
||||||
# For security reasons, this must be done before checking out the PR branch.
|
|
||||||
- name: Build manager
|
- name: Build manager
|
||||||
env:
|
env:
|
||||||
GO_BUILD_FLAGS: -o $MANAGER_PATH
|
GO_BUILD_FLAGS: -o $MANAGER_PATH
|
||||||
run: task go:build
|
run: task go:build
|
||||||
|
|
||||||
- name: Checkout PR branch
|
- name: Download diff
|
||||||
run: |
|
uses: actions/download-artifact@v2
|
||||||
# https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally
|
with:
|
||||||
# It's necessary to reference both pull_request.number and issue.number because only one of the two are defined depending on whether the workflow is triggered by PR or comment event.
|
path: ${{ needs.diff.outputs.path }}
|
||||||
git fetch origin pull/${{ github.event.pull_request.number }}${{ github.event.issue.number }}/head:pr-branch
|
name: ${{ needs.diff.outputs.artifact }}
|
||||||
git checkout pr-branch
|
|
||||||
|
|
||||||
- name: Parse request
|
- name: Parse request
|
||||||
id: parse-request
|
id: parse-request
|
||||||
run: |
|
run: |
|
||||||
REQUEST="$("$MANAGER_PATH" --baseref="${{ github.sha }}" --repopath="${{ github.workspace }}" --listname="repositories.txt")"
|
REQUEST="$("$MANAGER_PATH" --diffpath="${{ needs.diff.outputs.path }}/${{ needs.diff.outputs.filename }}" --repopath="${{ github.workspace }}" --listname="repositories.txt")"
|
||||||
# Due to limitations of the GitHub Actions workflow system, dedicated outputs must be created for use in certain workflow fields.
|
# Due to limitations of the GitHub Actions workflow system, dedicated outputs must be created for use in certain workflow fields.
|
||||||
echo "::set-output name=type::$(echo "$REQUEST" | jq -r -c '.type')"
|
echo "::set-output name=type::$(echo "$REQUEST" | jq -r -c '.type')"
|
||||||
echo "::set-output name=submissions::$(echo "$REQUEST" | jq -c '.submissions')"
|
echo "::set-output name=submissions::$(echo "$REQUEST" | jq -c '.submissions')"
|
||||||
|
@ -75,50 +75,46 @@ type submissionType struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Command line flags.
|
// Command line flags.
|
||||||
var baseRef = flag.String("baseref", "", "")
|
var diffPathArgument = flag.String("diffpath", "", "")
|
||||||
var repoPath = flag.String("repopath", "", "")
|
var repoPathArgument = flag.String("repopath", "", "")
|
||||||
var listName = flag.String("listname", "", "")
|
var listNameArgument = flag.String("listname", "", "")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Validate flag input.
|
// Validate flag input.
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *baseRef == "" {
|
if *diffPathArgument == "" {
|
||||||
errorExit("--baseref flag is required")
|
errorExit("--diffpath flag is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if *repoPath == "" {
|
if *repoPathArgument == "" {
|
||||||
errorExit("--repopath flag is required")
|
errorExit("--repopath flag is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if *listName == "" {
|
if *listNameArgument == "" {
|
||||||
errorExit("--listname flag is required")
|
errorExit("--listname flag is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
listPath := paths.New(*repoPath, *listName)
|
diffPath := paths.New(*diffPathArgument)
|
||||||
exist, err := listPath.ExistCheck()
|
exist, err := diffPath.ExistCheck()
|
||||||
if err != nil {
|
if !exist {
|
||||||
panic(err)
|
errorExit("diff file not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listPath := paths.New(*repoPathArgument, *listNameArgument)
|
||||||
|
exist, err = listPath.ExistCheck()
|
||||||
if !exist {
|
if !exist {
|
||||||
errorExit(fmt.Sprintf("list file %s not found", listPath))
|
errorExit(fmt.Sprintf("list file %s not found", listPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the PR diff.
|
|
||||||
err = os.Chdir(*repoPath)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rawDiff, err := exec.Command("git", "diff", "--unified=0", "--ignore-blank-lines", "--ignore-space-at-eol", *baseRef).Output()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the PR diff.
|
// Parse the PR diff.
|
||||||
|
rawDiff, err := diffPath.ReadFile()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
var request requestType
|
var request requestType
|
||||||
var submissionURLs []string
|
var submissionURLs []string
|
||||||
request.Type, submissionURLs = parseDiff(rawDiff, *listName)
|
request.Type, submissionURLs = parseDiff(rawDiff, *listNameArgument)
|
||||||
|
|
||||||
// Process the submissions.
|
// Process the submissions.
|
||||||
var indexEntries []string
|
var indexEntries []string
|
||||||
|
Reference in New Issue
Block a user