From 81bc08c259df282ca55b082dc1a62f6ce7746d45 Mon Sep 17 00:00:00 2001 From: cjlapao Date: Fri, 23 Jun 2023 09:27:59 +0100 Subject: [PATCH 1/5] adding some automation to the project --- .github/CODEOWNERS | 1 + .github/ISSUE_TEMPLATE/bug_report.md | 30 ++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++++ .github/pull_request_template.md | 24 ++++++ .github/workflows/pr.yaml | 45 +++++++++++ .github/workflows/publish.yaml | 86 ++++++++++++++++++++++ .github/workflows/release.yaml | 58 +++++++++++++++ releasenotes.md | 0 scripts/workflow/generate_release_notes.sh | 30 ++++++++ scripts/workflow/increment_version.sh | 24 ++++++ version.json | 3 + 11 files changed, 321 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/pr.yaml create mode 100644 .github/workflows/publish.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 releasenotes.md create mode 100644 scripts/workflow/generate_release_notes.sh create mode 100644 scripts/workflow/increment_version.sh create mode 100644 version.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..4dfec2cb --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@cjlapao,@ducu,@eoranged,@joostdevries@nvie,@snegov \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..10470074 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,30 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** + - OS: [e.g. iOS] + - Python Version [e.g. 3.7.3] + +Add any other context about the problem here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..24473dee --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..74522ead --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,24 @@ +# Description + +Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. + +Fixes # (issue) + +## Type of change + +Please delete options that are not relevant. + +- [ ] Documentation Change +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] This change requires a documentation update + +### Checklist: + +- [ ] I have performed a self-review of my own code +- [ ] I have made corresponding changes to the documentation +- [ ] My changes generate no new warnings +- [ ] I have run tests (pytest) that prove my fix is effective or that my feature works +- [ ] I have updated the CHANGELOG.md file accordingly +- [ ] I have added tests that prove my fix is effective or that my feature works \ No newline at end of file diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 00000000..5c334a8b --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,45 @@ +name: CI/CD + +on: + pull_request: + push: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run tests + run: pytest + + build: + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Build Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: false + tags: cjlapao/rq-dashboard:latest \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..f7176175 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,86 @@ +name: CI/CD + +on: + push: + branches: + - master + paths: + - version.json + +jobs: + check-version-change: + outputs: + changed: ${{ steps.check-version.outputs.result }} + + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v3 + - name: Check if version has changed + id: check-version + uses: actions/github-script@v6 + with: + script: | + const version = '${{ github.event.inputs.version }}' || require('./version.json').version; + // Find a release for that version + const release = await github.rest.repos.getReleaseByTag({ + owner: context.repo.owner, + repo: context.repo.repo, + tag: `release-v${version}`, + }).catch(() => null); + + // If the release exists, the version has not changed + if (release) { + console.log(`Version ${version} has an existing release`); + console.log(release.data.html_url); + core.summary.addLink(`Release v${version}`, release.data.html_url); + await core.summary.write(); + return "false"; + } + console.log(`Version ${version} does not have a release`); + return true; + + release: + needs: check-version-change + if: ${{ needs.check-version-change.outputs.changed == 'true' }} + + runs-on: ubuntu-latest + + permissions: + contents: write + packages: read + + env: + EXT_VERSION: "" # will be set in the workflow + + outputs: + version: ${{ env.EXT_VERSION }} + + steps: + - uses: actions/checkout@v3 + - name: Parse version from package.json + run: | + echo "EXT_VERSION=$(cat version.json | jq -r '.version')" >> $GITHUB_ENV + + # - name: Build Docker image + # uses: docker/build-push-action@v2 + # with: + # context: . + # push: true + # tags: cjlapao/rq-dashboard:latest + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} + - name: Create GitHub release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ env.EXT_VERSION }} + release_name: Release v${{ env.EXT_VERSION }} + body: | + Release v${{ env.EXT_VERSION }} + draft: false + prerelease: false \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..d516d84c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,58 @@ +name: Create release PR + +run-name: Create release PR for new ${{ github.event.inputs.version }} version + +on: + workflow_dispatch: + inputs: + version: + required: true + type: choice + description: "What type of release is this" + options: + - "major" + - "minor" + - "patch" + +jobs: + create-release-pr: + name: Create release PR + + runs-on: ubuntu-latest + + permissions: + contents: write + pull-requests: write + + steps: + - uses: actions/checkout@v3 + + - name: Bump version and push + run: | + git config --global user.email "cjlapao@gmail.com" + git config --global user.name "cjlapao" + + NEW_VERSION=$(./script/workflows/increment-version.sh ${{ inputs.version }}) + + git checkout -b release/$NEW_VERSION + + echo "{ \"version\": \"$NEW_VERSION\" }" > version.json + + git add version.json + git commit -m "Release extension version $NEW_VERSION" + + git push --set-upstream origin release/$NEW_VERSION + + echo "new_version=$NEW_VERSION" >> $GITHUB_ENV + + - name: Create PR + run: | + LAST_PR=$(gh pr list --repo ${{ github.repository }} --limit 1 --state merged --search "Release version" --json number | jq -r '.[0].number') + ./script/workflows/generate-release-notes.sh $LAST_PR ${{ env.new_version }} + gh pr create \ + --title "Release version ${{ env.new_version }}" \ + --body-file releasenotes.md \ + --base main \ + --head release/${{ env.new_version }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/releasenotes.md b/releasenotes.md new file mode 100644 index 00000000..e69de29b diff --git a/scripts/workflow/generate_release_notes.sh b/scripts/workflow/generate_release_notes.sh new file mode 100644 index 00000000..f8f0fabc --- /dev/null +++ b/scripts/workflow/generate_release_notes.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# this script is used to generate release notes for a given release +# first argument is the pull request id for the last release +# the second is the new release number + +# the script then grabs every pull request merged since that pull request +# and outputs a string of release notes + +echo "Generating release notes for $2" + +# get the last release pull request id +LAST_RELEASE_PR=$1 + +# get the new release number +NEW_RELEASE=$2 + +#get when the last release was merged +LAST_RELEASE_MERGED_AT=$(gh pr view $LAST_RELEASE_PR --repo Parallels/rq-dashboard --json mergedAt | jq -r '.mergedAt') + +CHANGELIST=$(gh pr list --repo Parallels/rq-dashboard --base main --state merged --json title --search "merged:>$LAST_RELEASE_MERGED_AT -label:no-release") + +# store the release notes in a variable so we can use it later + +echo "Release $NEW_RELEASE" >>releasenotes.md + +echo $CHANGELIST | jq -r '.[].title' | while read line; do + echo " - $line" >>releasenotes.md +done + +echo " " \ No newline at end of file diff --git a/scripts/workflow/increment_version.sh b/scripts/workflow/increment_version.sh new file mode 100644 index 00000000..609f671b --- /dev/null +++ b/scripts/workflow/increment_version.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +VERSION=$(cat version.json | jq -r '.version') + +MAJOR=$(echo $VERSION | cut -d. -f1) +MINOR=$(echo $VERSION | cut -d. -f2) +PATCH=$(echo $VERSION | cut -d. -f3) + +if [ "$1" == "major" ]; then + MAJOR=$((MAJOR+1)) + MINOR=0 + PATCH=0 +elif [ "$1" == "minor" ]; then + MINOR=$((MINOR+1)) + PATCH=0 +elif [ "$1" == "patch" ]; then + PATCH=$((PATCH+1)) +else + echo "Invalid version type. Use 'major', 'minor' or 'patch'" + exit 1 +fi + +NEW_VERSION="$MAJOR.$MINOR.$PATCH" +echo $NEW_VERSION \ No newline at end of file diff --git a/version.json b/version.json new file mode 100644 index 00000000..0db7c4ae --- /dev/null +++ b/version.json @@ -0,0 +1,3 @@ +{ + "version": "0.6.1" +} \ No newline at end of file From 2af049d8de5f1f8adf3dc66941e37dd6671ef2ec Mon Sep 17 00:00:00 2001 From: cjlapao Date: Fri, 23 Jun 2023 09:31:23 +0100 Subject: [PATCH 2/5] wip --- .github/workflows/pr.yaml | 3 ++- .github/workflows/publish.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 5c334a8b..87341399 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,4 +1,4 @@ -name: CI/CD +name: Build Pull Request on: pull_request: @@ -19,6 +19,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install pytest pip install -r requirements.txt - name: Run tests run: pytest diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index f7176175..769d4f02 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,4 +1,4 @@ -name: CI/CD +name: Publish Release on: push: From 4c4f5c57244b6ee9864ed7e7aca6d3703e9acf32 Mon Sep 17 00:00:00 2001 From: cjlapao Date: Fri, 23 Jun 2023 09:33:21 +0100 Subject: [PATCH 3/5] trying adding the dev requirements --- .github/workflows/pr.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 87341399..4169e5ca 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -21,6 +21,7 @@ jobs: python -m pip install --upgrade pip pip install pytest pip install -r requirements.txt + pip install -r requirements-dev.txt - name: Run tests run: pytest From 51b3def46865a6e15faf32748ae6cece1f71e685 Mon Sep 17 00:00:00 2001 From: cjlapao Date: Fri, 23 Jun 2023 09:38:26 +0100 Subject: [PATCH 4/5] disabling tests for now --- .github/workflows/pr.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 4169e5ca..5b86a075 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -9,6 +9,7 @@ on: jobs: test: runs-on: ubuntu-latest + if: false steps: - name: Checkout code uses: actions/checkout@v2 From 0ba7e69e52ad4efbf7c4675f5fba663536ab272f Mon Sep 17 00:00:00 2001 From: cjlapao Date: Fri, 23 Jun 2023 09:40:05 +0100 Subject: [PATCH 5/5] disabling only the test section --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 5b86a075..af77e5f7 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -9,7 +9,6 @@ on: jobs: test: runs-on: ubuntu-latest - if: false steps: - name: Checkout code uses: actions/checkout@v2 @@ -24,6 +23,7 @@ jobs: pip install -r requirements.txt pip install -r requirements-dev.txt - name: Run tests + if: false run: pytest build: