diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c7ce55f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +env: + PYTHON_VERSION: "3.15" + NODE_VERSION: "26.13.0" + RUFF_VERSION: "0.17.3" + PLAYWRIGHT_VERSION: "1.64.1" + +jobs: + lint: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Ruff + run: pipx run "ruff==${RUFF_VERSION}" check --select E9,F repo-stats + - name: ShellCheck + run: shellcheck release_notes_generator.sh + + test: + runs-on: ubuntu-24.04 + defaults: + run: + working-directory: repo-stats + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: ${{ env.PYTHON_VERSION }} + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: ${{ env.NODE_VERSION }} + - name: Install Playwright + Chromium (for browser tests) + run: | + npm install --no-save --no-package-lock "playwright@${PLAYWRIGHT_VERSION}" + npx playwright install --with-deps chromium + - name: Run tests + run: python3 -m unittest discover -s tests -v diff --git a/release_notes_generator.sh b/release_notes_generator.sh index 7cf8b3b..62fdd3b 100644 --- a/release_notes_generator.sh +++ b/release_notes_generator.sh @@ -1,6 +1,6 @@ #!/bin/bash -read -r -d '' USAGE << EOM +read -r -d '' USAGE << 'EOM' Usage: release_notes_helper.sh [-j JIRAKEY] [-s SCOPES] [END_VERSION] example 1 (from a release tag to main, for an upcoming tag): ./release_notes_helper.sh v1.1.0 origin/main @@ -26,18 +26,18 @@ while getopts ":j:s:h" opt; do ;; h) echo "${USAGE}" && exit 0 ;; - \? ) echo "${USAGE}" && exit -2 + \? ) echo "${USAGE}" && exit 2 ;; esac done -START_VERSION=${@:$OPTIND:1} +START_VERSION=${*:$OPTIND:1} if [ -z "${START_VERSION}" ]; then echo "${USAGE}" - exit -1 + exit 1 fi -END_VERSION=${@:$OPTIND+1:1} +END_VERSION=${*:$OPTIND+1:1} if [ -z "${END_VERSION}" ]; then END_VERSION="HEAD" fi @@ -59,7 +59,7 @@ echo "" echo "Generating release notes from ${START_VERSION} to ${END_VERSION}" echo "Copy the lines below into the release notes." echo "-----" -git log ${START_VERSION}...${END_VERSION} --pretty=format:"- [(%h)](${CI_PROJECT_URL}/commit/%H) %s" --reverse | +git log "${START_VERSION}...${END_VERSION}" --pretty=format:"- [(%h)](${CI_PROJECT_URL}/commit/%H) %s" --reverse | grep "${SCOPES}" | sort -k 3,3 | sed -e $'s/*/\\n */g' | @@ -93,9 +93,9 @@ git log ${START_VERSION}...${END_VERSION} --pretty=format:"- [(%h)](${CI_PROJECT echo "-----" # TODO: remove blanks when Issue does not exist -issues=($(git log ${START_VERSION}...${END_VERSION} --pretty=format:'%s' --reverse | grep -oe "${ISSUEPREFIX}[0-9]\+")) -unique=($(echo "${issues[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) +mapfile -t issues < <(git log "${START_VERSION}...${END_VERSION}" --pretty=format:'%s' --reverse | grep -oe "${ISSUEPREFIX}[0-9]\+") +mapfile -t unique < <(printf '%s\n' "${issues[@]}" | grep . | sort -u) echo "Commit range includes ${#unique[@]} Issues" list=$(IFS=, ; echo "${unique[*]}") # If JIRAKEY is set, output JIRA query -[[ ! -z "$JIRAKEY" ]] && echo "project=${JIRAKEY} and id in (${list})" +[[ -n "$JIRAKEY" ]] && echo "project=${JIRAKEY} and id in (${list})" diff --git a/repo-stats/tests/test_ui.py b/repo-stats/tests/test_ui.py index 6d9ebda..b40636c 100644 --- a/repo-stats/tests/test_ui.py +++ b/repo-stats/tests/test_ui.py @@ -21,7 +21,7 @@ from typing import Any, Iterable, Mapping, Sequence, cast import helpers -from helpers import add_remote, collect, rs +from helpers import collect, rs import fixtures from fixtures import DAY, Repo, lines import mock_servers as ms @@ -242,7 +242,6 @@ def build_api_data() -> dict[str, Any]: created = merged - int(rnd.lognormvariate(10.5, 1.0)) first_commit = created - int(rnd.uniform(600, 90000)) ready = created + int(rnd.choice([0, 0, 0, 1800, 20000])) - state = "MERGED" author, atype = "alice", "User" if i % 10 == 3: author, atype = "dependabot[bot]", "Bot"