Skip to content

Commit

Permalink
Add updated workflow files
Browse files Browse the repository at this point in the history
  • Loading branch information
chkim-usgs committed Nov 26, 2024
1 parent f056bce commit 28e6b1b
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 18 deletions.
46 changes: 32 additions & 14 deletions .github/pr_label_checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re as rgx
from itertools import chain
from requests import get, post
from requests import Response
from requests.exceptions import HTTPError, RequestException
Expand All @@ -8,12 +9,15 @@
# Constants
GITHUB_TOKEN=os.environ["GITHUB_TOKEN"]
GITHUB_API_URL=os.environ["GITHUB_API_URL"]
GITHUB_SERVER_URL=os.environ["GITHUB_SERVER_URL"]
GITHUB_SHA=os.environ["GITHUB_SHA"]

BASE_URL=f'{GITHUB_API_URL}/repos/DOI-USGS/ISIS3'
PULLS_URL=f'{BASE_URL}/pulls'
COMMITS_URL=f'{BASE_URL}/commits'
ISSUES_URL=f'{BASE_URL}/issues'
REPO_URL_PATH='DOI-USGS/ISIS3'
API_BASE_URL=f'{GITHUB_API_URL}/repos/{REPO_URL_PATH}'
API_PULLS_URL=f'{API_BASE_URL}/pulls'
API_COMMITS_URL=f'{API_BASE_URL}/commits'
API_ISSUES_URL=f'{API_BASE_URL}/issues'
ISSUES_URL=f'{GITHUB_SERVER_URL}/{REPO_URL_PATH}/issues/'
HEADERS = {
"Accept": "application/vnd.github+json",
"Authorization" : f"Bearer {GITHUB_TOKEN}",
Expand All @@ -25,7 +29,7 @@ def get_prs_associated_with_commit() -> Response:
Get list of PRs associated with commit.
"""
try:
response = get(f'{COMMITS_URL}/{GITHUB_SHA}/pulls', headers=HEADERS)
response = get(f'{API_COMMITS_URL}/{GITHUB_SHA}/pulls', headers=HEADERS)
response.raise_for_status()
return response
except HTTPError as he:
Expand All @@ -52,16 +56,30 @@ def search_for_linked_issues(pull_body: str) -> list:
Regex examples:
'#1' - matches
'#123456' - matches
'https://github.com/DOI-USGS/ISIS3/issues/25' - matches
'# 123' - fails
'#ABC' - fails
'## ABC'- fails
"""
linked_issues = rgx.findall('#[^\D]\d*', pull_body)
issue_numbers = []
for linked_issue in linked_issues:
# Strip linked issue text of '#'
issue_numbers.append(linked_issue.replace('#',''))
return issue_numbers
# Split the PR body by heading
pull_body_list = pull_body.split('##')
regex_pattern = rf'{ISSUES_URL}(\d)|(#[^\D]\d*)'
for section in pull_body_list:
# Find section with heading 'Related Issue'
if section != None and 'Related Issue' in section:
# Find items that match the regex pattern
matched_items = rgx.findall(regex_pattern, section)
# Convert list of tuples to list of all items
flattened_list = list(chain.from_iterable(matched_items))
# Remove items of empty values
filtered_list = list(filter(None, flattened_list))
# Remove '#' from items
issue_numbers = list(map(lambda item: item.replace('#', ''), filtered_list))
return issue_numbers
# No linked issues
print(False)
sys.exit(0)


def get_linked_issues(issue_numbers: list) -> list:
"""
Expand All @@ -71,7 +89,7 @@ def get_linked_issues(issue_numbers: list) -> list:
for issue_number in issue_numbers:
# Get labels from issue
try:
response = get(f'{ISSUES_URL}/{issue_number}', headers=HEADERS)
response = get(f'{API_ISSUES_URL}/{issue_number}', headers=HEADERS)
response.raise_for_status()
response_list.append(response)
except HTTPError as he:
Expand Down Expand Up @@ -109,7 +127,7 @@ def update_pr_labels(pull_number: str, combined_issue_labels: list):
# Convert label list into JSON-formatted dict
labels_data = {"labels": combined_issue_labels}
try:
response = post(f'{ISSUES_URL}/{pull_number}/labels', json=labels_data, headers=HEADERS)
response = post(f'{API_ISSUES_URL}/{pull_number}/labels', json=labels_data, headers=HEADERS)
response.raise_for_status()
except HTTPError as he:
raise HTTPError("HTTPError in updating PR.", he)
Expand All @@ -121,7 +139,7 @@ def get_pr(pull_number: str) -> Response:
Get pull request
"""
try:
response = get(f'{PULLS_URL}/{pull_number}', headers=HEADERS)
response = get(f'{API_PULLS_URL}/{pull_number}', headers=HEADERS)
response.raise_for_status()
return response
except HTTPError as he:
Expand Down
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
- [ ] My change requires a change to the documentation and I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] I have added myself to the [.zenodo.json](https://github.com/USGS-Astrogeology/ISIS3/blob/dev/.zenodo.json) document.
- [ ] I have added any user impacting changes to the [CHANGELOG.md](https://github.com/USGS-Astrogeology/ISIS3/blob/dev/CHANGELOG.md) document.
- [ ] I have added my user impacting change to the [CHANGELOG.md](https://github.com/USGS-Astrogeology/ISIS3/blob/dev/CHANGELOG.md) document. <!--- NOTE: You can only have one changelog entry per PR, see https://github.com/DOI-USGS/ISIS3/blob/dev/CONTRIBUTING.md -->


## Licensing
This project is mostly composed of free and unencumbered software released into the public domain, and we are unlikely to accept contributions that are not also released into the public domain. Somewhere near the top of each file should have these words:
Expand Down
2 changes: 1 addition & 1 deletion .github/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==2.28.2
requests==2.32.0
1 change: 1 addition & 0 deletions .github/workflows/autopr_bugfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_API_URL: ${{ secrets.GITHUB_API_URL }}
GITHUB_SERVER_URL: ${{ secrets.GITHUB_SERVER_URL }}
GITHUB_SHA: ${{ secrets.GITHUB_SHA }}
run: |
echo "result=$(python ./.github/pr_label_checker.py)" >> $GITHUB_OUTPUT
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/gitlab-codebuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Github to Gitlab CI - Run CodeBuild

env:
PR_NUMBER: ${{ github.event.number }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}

on:
pull_request_target:
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Run script
run: |
git config --global user.name "Github_CI"
git config --global user.email "project_14468_bot_3f7d8e1a392afd88ead5f3f3154e809d@noreply.gitlab.com"
git clone https://isis-codebuild-ci:[email protected]/astrogeology/isis-codebuild-ci.git
cd isis-codebuild-ci
git checkout -b PR_$PR_NUMBER
echo -e "\nenv: \n shell: bash \n variables: \n PR_NUMBER: $PR_NUMBER \n MERGE_BRANCH: $GITHUB_BASE_REF" >> buildspec.yml
git commit -a -m "$PR_NUMBER"
git push origin PR_$PR_NUMBER --force
comment-bot:
permissions: write-all
runs-on: [ubuntu-latest]
needs: [build]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
The build and test suite have started for your pull request.
To view your [build log](https://us-west-2.codebuild.aws.amazon.com/project/eyJlbmNyeXB0ZWREYXRhIjoiNDJNZ2MxbHFKTkwxV1RyQUxJekdJY3FIanNqU29rMHB4Nk1YUzk4REIrZUZDeEtEaW9HQlZ1dTZOSHpML2VUTGVDekYydmVFcU9sUHJKN20wQzd1Q0UzSzJscnB0MElDb1M3Ti9GTlJYR1RuMWJTV3V1SkJTa3NoYmc9PSIsIml2UGFyYW1ldGVyU3BlYyI6IjF3U2NTSGlDcEtCc29YVnEiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D), please reference the build with source version: "PR_${{ github.event.number }}".
Additionally, check the latest "dev" source version to identify existing test failures. Please note that you are not responsible for the test failures that exist on both your PR and the dev branch.
32 changes: 32 additions & 0 deletions .github/workflows/gitlab-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Github to Gitlab CI - Run CodeBuild

env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}

on:
release:
types: [prereleased, released]
push:
branches:
- '*.*.*_RC*'
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Run script
env:
ISIS_VERSION: ${{ github.event.release.tag_name || github.ref_name }}
run: |
git config --global user.name "Github_CI"
git config --global user.email "project_14468_bot_3f7d8e1a392afd88ead5f3f3154e809d@noreply.gitlab.com"
git clone https://isis-codebuild-ci:[email protected]/astrogeology/isis-codebuild-ci.git
echo $ISIS_VERSION
cd isis-codebuild-ci
git checkout -b RELEASE_$ISIS_VERSION
echo -e "\nenv: \n shell: bash \n variables: \n ISIS_VERSION: $ISIS_VERSION \n ANACONDA_API_TOKEN: $ANACONDA_TOKEN" >> buildspec-release.yml
git commit -a -m "$ISIS_VERSION"
git push origin RELEASE_$ISIS_VERSION --force
4 changes: 2 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 180
days-before-close: 180
stale-issue-message: "Thank you for your contribution!\n\nUnfortunately, this issue hasn't received much attention lately, so it is labeled as 'stale.'\n\nIf no additional action is taken, this issue will be automatically closed in 180 days."
stale-pr-message: "Thank you for your contribution!\n\nUnfortunately, this pull request hasn't received much attention lately, so it is labeled as 'stale.'\n\nIf no additional action is taken, this pull request will be automatically closed in 180 days."
stale-issue-message: "Thank you for your contribution!\n\nUnfortunately, this issue hasn't received much attention lately, so it is labeled as 'stale.'\n\nIf no additional action is taken, this issue will be automatically closed in 180 days.\n\nIf you want to participate in our support prioritization meetings or be notified when support sprints are happening, you can sign up the support sprint notification emails [here](https://public.govdelivery.com/accounts/USDOIGS/signup/39118).\n\nRead more about our support processs [here](https://astrogeology.usgs.gov/docs/how-to-guides/software-management/software-support/)"
stale-pr-message: "Thank you for your contribution!\n\nUnfortunately, this pull request hasn't received much attention lately, so it is labeled as 'stale.'\n\nIf no additional action is taken, this pull request will be automatically closed in 180 days.\n\nIf you want to participate in our support prioritization meetings or be notified when support sprints are happening, you can sign up the support sprint notification emails [here](https://public.govdelivery.com/accounts/USDOIGS/signup/39118).\n\n Read more about our support processs [here](https://astrogeology.usgs.gov/docs/how-to-guides/software-management/software-support/)"
stale-issue-label: 'inactive'
stale-pr-label: 'inactive'

26 changes: 26 additions & 0 deletions .github/workflows/version_bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: versionbump
on:
pull_request:
branches:
- lts
types:
- closed

jobs:
version_bump:
if: github.event.pull_request.merged && ${{ github.event.label.name == 'bug' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Bump version
run: |
git config --global user.name 'ProjectBot'
git config --global user.email '[email protected]'
CURRENTVERSION=$(sed -n '0,/^{%[[:space:]]*set[[:space:]]*version[[:space:]]*=[[:space:]]*"\([^"]*\)"[[:space:]]*%}/s//\1/p' ${{github.workspace}}/recipe/meta.yaml)
CURRENTVERSION=`echo $CURRENTVERSION | awk -F. '/[0-9]+\./{$NF;print}' OFS=.`
NEWVERSION=`echo $CURRENTVERSION | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.`
sed -i "0,/^{%.*version.*\"\([^\"]*\)\".*/s//{% set version = "\"${NEWVERSION}"\" %}/" ${{github.workspace}}/recipe/meta.yaml
sed -i "0,/set(VERSION.*/s//set(VERSION \""${NEWVERSION}"\")/" ${{github.workspace}}/isis/CMakeLists.txt
git add ${{github.workspace}}/isis/CMakeLists.txt ${{github.workspace}}/recipe/meta.yaml
git commit -m 'auto bump version'
git push

0 comments on commit 28e6b1b

Please sign in to comment.