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

Allow re-running of workflows #158

Merged
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
61 changes: 59 additions & 2 deletions .github/workflows/sync-rest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,27 @@ jobs:
with:
result-encoding: string
script: |
const title = `[Tracking] ${context.workflow} - ${context.eventName} - ${context.actor} - ${context.sha}`
const label = '👁 tracking issue'

const existingIssue = (await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
labels: label,
state: 'open',
})).find((issue) => issue.title === title)

if (existingIssue) {
console.log(`::notice::Existing issue found: ${existingIssue.html_url}`)
return existingIssue.html_url
}

const issue = (await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `[Tracking] ${context.workflow} - ${context.eventName} - ${context.actor} - ${context.sha}`,
title: title,
body: `Workflow run: https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
labels: ['👁 tracking issue']
labels: [label]
})).data

return issue.html_url
Expand Down Expand Up @@ -151,12 +166,48 @@ jobs:
repo: ${{ fromJson(needs.fetch-repos.outputs.repos) }}

steps:
- name: Check if pull request has already been opened
id: pr-already-exists
uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e
env:
TARGET_REPO_FULLNAME: ${{ matrix.repo }}
TRACKING_ISSUE_URL: ${{ needs.open-tracking-issue.outputs.issue-url }}
with:
github-token: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
script: |
const repo = process.env.TARGET_REPO_FULLNAME.split('/')[1]

const existingPr = (
await github.paginate(github.rest.issues.listForRepo, {
owner: "exercism",
repo: repo,
state: 'open',
})
).find((pr) =>
pr.body && pr.body.includes(process.env.TRACKING_ISSUE_URL)
)

if (existingPr) {
console.log(`::notice::Existing pull request found: ${existingPr.html_url}`)
return true
}

return false

############################################################
# ONLY RUN THE REST OF THE SCRIPT IF THE PR DOES NOT EXIST #
# All following steps must have: #
# if: steps.pr-already-exists.outputs.result == 'false' #
###########################################################

- name: Checkout main repo
if: steps.pr-already-exists.outputs.result == 'false'
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
with:
path: main

- name: Checkout target repo
if: steps.pr-already-exists.outputs.result == 'false'
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
with:
repository: ${{ matrix.repo }}
Expand All @@ -165,6 +216,7 @@ jobs:
fetch-depth: 0

- name: Checkout new branch on track repo
if: steps.pr-already-exists.outputs.result == 'false'
id: branch
run: |
cd track-repo
Expand All @@ -177,10 +229,12 @@ jobs:
echo "::set-output name=name::$branch"

- name: Copy globally synced files to target repo
if: steps.pr-already-exists.outputs.result == 'false'
run: |
cp -a main/global-files/. track-repo/

- name: Determine if repo is a tooling repo
if: steps.pr-already-exists.outputs.result == 'false'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not added this check to the steps that check for the repo being a tooling or track repo, as steps.is-tooling-repo.outputs.result == 'true' will be false anyway due to the step where that result is used. The same goes for the last steps that all check for steps.changes.outputs.changes == 'true', which will always be false due to the step to set that to true not being executed if the PR already exists

id: is-tooling-repo
uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e
env:
Expand All @@ -201,6 +255,7 @@ jobs:
cp -a main/tooling-files/. track-repo/

- name: Determine if repo is a track repo
if: steps.pr-already-exists.outputs.result == 'false'
id: is-track-repo
uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e
env:
Expand All @@ -221,11 +276,13 @@ jobs:
cp -a main/tracks-files/. track-repo/

- name: Apply transformations based on track config
if: steps.pr-already-exists.outputs.result == 'false'
env:
TRACK: ${{ matrix.repo }}
run: julia --color=yes main/scripts/apply-track-config.jl

- name: Check for changes
if: steps.pr-already-exists.outputs.result == 'false'
id: changes
run: |
cd track-repo
Expand Down
59 changes: 57 additions & 2 deletions .github/workflows/sync-tooling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,27 @@ jobs:
with:
result-encoding: string
script: |
const title = `[Tracking] ${context.workflow} - ${context.eventName} - ${context.actor} - ${context.sha}`
const label = '👁 tracking issue'

const existingIssue = (await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
labels: label,
state: 'open',
})).find((issue) => issue.title === title)

if (existingIssue) {
console.log(`::notice::Existing issue found: ${existingIssue.html_url}`)
return existingIssue.html_url
}

const issue = (await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `[Tracking] ${context.workflow} - ${context.eventName} - ${context.actor} - ${context.sha}`,
title: title,
body: `Workflow run: https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
labels: ['👁 tracking issue']
labels: [label]
})).data

return issue.html_url
Expand Down Expand Up @@ -141,12 +156,48 @@ jobs:
repo: ${{ fromJson(needs.fetch-repos.outputs.repos) }}

steps:
- name: Check if pull request has already been opened
id: pr-already-exists
uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e
env:
TARGET_REPO_FULLNAME: ${{ matrix.repo }}
TRACKING_ISSUE_URL: ${{ needs.open-tracking-issue.outputs.issue-url }}
with:
github-token: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
script: |
const repo = process.env.TARGET_REPO_FULLNAME.split('/')[1]

const existingPr = (
await github.paginate(github.rest.issues.listForRepo, {
owner: "exercism",
repo: repo,
state: 'open',
})
).find((pr) =>
pr.body && pr.body.includes(process.env.TRACKING_ISSUE_URL)
)

if (existingPr) {
console.log(`::notice::Existing pull request found: ${existingPr.html_url}`)
return true
}

return false

############################################################
# ONLY RUN THE REST OF THE SCRIPT IF THE PR DOES NOT EXIST #
# All following steps must have: #
# if: steps.pr-already-exists.outputs.result == 'false' #
###########################################################

- name: Checkout main repo
if: steps.pr-already-exists.outputs.result == 'false'
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
with:
path: main

- name: Checkout target repo
if: steps.pr-already-exists.outputs.result == 'false'
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
with:
repository: ${{ matrix.repo }}
Expand All @@ -155,6 +206,7 @@ jobs:
fetch-depth: 0

- name: Checkout new branch on track repo
if: steps.pr-already-exists.outputs.result == 'false'
id: branch
run: |
cd track-repo
Expand All @@ -167,16 +219,19 @@ jobs:
echo "::set-output name=name::$branch"

- name: Copy synced files to target repo
if: steps.pr-already-exists.outputs.result == 'false'
run: |
cp -a main/global-files/. track-repo/
cp -a main/tooling-files/. track-repo/

- name: Apply transformations based on track config
if: steps.pr-already-exists.outputs.result == 'false'
env:
TRACK: ${{ matrix.repo }}
run: julia --color=yes main/scripts/apply-track-config.jl

- name: Check for changes
if: steps.pr-already-exists.outputs.result == 'false'
id: changes
run: |
cd track-repo
Expand Down
59 changes: 57 additions & 2 deletions .github/workflows/sync-tracks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,27 @@ jobs:
with:
result-encoding: string
script: |
const title = `[Tracking] ${context.workflow} - ${context.eventName} - ${context.actor} - ${context.sha}`
const label = '👁 tracking issue'

const existingIssue = (await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
labels: label,
state: 'open',
})).find((issue) => issue.title === title)

if (existingIssue) {
console.log(`::notice::Existing issue found: ${existingIssue.html_url}`)
return existingIssue.html_url
}

const issue = (await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `[Tracking] ${context.workflow} - ${context.eventName} - ${context.actor} - ${context.sha}`,
title: title,
body: `Workflow run: https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
labels: ['👁 tracking issue']
labels: [label]
})).data

return issue.html_url
Expand Down Expand Up @@ -141,12 +156,48 @@ jobs:
repo: ${{ fromJson(needs.fetch-repos.outputs.repos) }}

steps:
- name: Check if pull request has already been opened
id: pr-already-exists
uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e
env:
TARGET_REPO_FULLNAME: ${{ matrix.repo }}
TRACKING_ISSUE_URL: ${{ needs.open-tracking-issue.outputs.issue-url }}
with:
github-token: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
script: |
const repo = process.env.TARGET_REPO_FULLNAME.split('/')[1]

const existingPr = (
await github.paginate(github.rest.issues.listForRepo, {
owner: "exercism",
repo: repo,
state: 'open',
})
).find((pr) =>
pr.body && pr.body.includes(process.env.TRACKING_ISSUE_URL)
)

if (existingPr) {
console.log(`::notice::Existing pull request found: ${existingPr.html_url}`)
return true
}

return false

############################################################
# ONLY RUN THE REST OF THE SCRIPT IF THE PR DOES NOT EXIST #
# All following steps must have: #
# if: steps.pr-already-exists.outputs.result == 'false' #
###########################################################

- name: Checkout main repo
if: steps.pr-already-exists.outputs.result == 'false'
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
with:
path: main

- name: Checkout target repo
if: steps.pr-already-exists.outputs.result == 'false'
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
with:
repository: ${{ matrix.repo }}
Expand All @@ -155,6 +206,7 @@ jobs:
fetch-depth: 0

- name: Checkout new branch on track repo
if: steps.pr-already-exists.outputs.result == 'false'
id: branch
run: |
cd track-repo
Expand All @@ -167,16 +219,19 @@ jobs:
echo "::set-output name=name::$branch"

- name: Copy synced files to target repo
if: steps.pr-already-exists.outputs.result == 'false'
run: |
cp -a main/global-files/. track-repo/
cp -a main/tracks-files/. track-repo/

- name: Apply transformations based on track config
if: steps.pr-already-exists.outputs.result == 'false'
env:
TRACK: ${{ matrix.repo }}
run: julia --color=yes main/scripts/apply-track-config.jl

- name: Check for changes
if: steps.pr-already-exists.outputs.result == 'false'
id: changes
run: |
cd track-repo
Expand Down