Skip to content

Commit

Permalink
Merge pull request #433 from Parallels/add-cicd-pipelines
Browse files Browse the repository at this point in the history
adding some automation to the project
  • Loading branch information
cjlapao authored Jun 23, 2023
2 parents 4254701 + 0ba7e69 commit f0059a1
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@cjlapao,@ducu,@eoranged,@joostdevries@nvie,@snegov
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 24 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build Pull Request

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 pytest
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run tests
if: false
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
86 changes: 86 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Publish Release

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
58 changes: 58 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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 }}
Empty file added releasenotes.md
Empty file.
30 changes: 30 additions & 0 deletions scripts/workflow/generate_release_notes.sh
Original file line number Diff line number Diff line change
@@ -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 " "
24 changes: 24 additions & 0 deletions scripts/workflow/increment_version.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "0.6.1"
}

0 comments on commit f0059a1

Please sign in to comment.