-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from MarkoSagadin/feature/ci
Added support for CI, drastically improving DEVX
- Loading branch information
Showing
9 changed files
with
372 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Label PR | ||
on: | ||
pull_request: | ||
types: [opened] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
pr-labeler: | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: TimonVS/pr-labeler-action@v4.1.1 | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Add lables (on the left) to the PRs of specific branches (on the right) | ||
pull request: feature/* | ||
release: release/* | ||
fix: fix/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: Build | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
checkout_ref: | ||
required: true | ||
type: string | ||
push: | ||
branches: | ||
- "main" | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
|
||
jobs: | ||
build-backend: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout last PR commit | ||
if: github.event_name == 'pull_request' | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Checkout last tag | ||
if: github.event_name == 'workflow_dispatch' | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.checkout_ref }} | ||
|
||
- name: Checkout main | ||
if: github.event_name == 'push' | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: main | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
cache: "pip" | ||
|
||
- name: Install dependencies | ||
run: make backend-install | ||
|
||
- name: Run tests | ||
run: make backend-test | ||
|
||
- name: Build binary wheel and a source tarball | ||
run: make backend-build | ||
|
||
- name: Package artefacts | ||
if: github.event_name == 'workflow_dispatch' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist/* | ||
|
||
build-frontend: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
matrix: | ||
node-version: ["14.x", "16.x", "18.x"] | ||
|
||
steps: | ||
- name: Checkout last PR commit | ||
if: github.event_name == 'pull_request' | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Checkout last tag | ||
if: github.event_name == 'workflow_dispatch' | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.checkout_ref }} | ||
|
||
- name: Checkout main | ||
if: github.event_name == 'push' | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: main | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: make frontend-install | ||
|
||
- name: Build | ||
run: make frontend-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: "Create Release" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: | ||
"The version you want to release [v##.##.##]? (BTW, did you update | ||
changelog?)" | ||
required: true | ||
env: | ||
GIT_TERMINAL_PROMPT: 0 | ||
|
||
jobs: | ||
update-changelog: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
with: | ||
# Fetch history for all branches and tags | ||
fetch-depth: 0 | ||
|
||
- name: Validate version input | ||
id: validate-input | ||
run: | | ||
# Check if input version is in correct format | ||
if [[ ! ${{ inputs.version }} =~ v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo "::error::Invalid input version: wrong format!" | ||
exit 1 | ||
fi | ||
# Check if input version already exists as git tag | ||
if [[ ! -z $(git tag | grep ${{ inputs.version }}) ]]; then | ||
echo "::error::Invalid input version: it already exists!" | ||
exit 1 | ||
fi | ||
- name: Update Changelog | ||
uses: thomaseizinger/keep-a-changelog-new-release@ec0871fec381db64ab389886ffe8e6fc2b661e2c | ||
with: | ||
tag: ${{ inputs.version }} | ||
|
||
- name: Commit Changelog, create tag and push | ||
run: | | ||
# In order to make a commit, we need to initialize a user. | ||
git config user.name "github-bot :robot:" | ||
git config user.email noreply@github.com | ||
git add CHANGELOG.md | ||
git commit -m "Update CHANGELOG.md for Release ${{ inputs.version }}" | ||
git tag ${{ inputs.version }} | ||
git push | ||
git push origin ${{ inputs.version }} | ||
call-build: | ||
needs: update-changelog | ||
uses: ./.github/workflows/build.yaml | ||
with: | ||
checkout_ref: ${{ inputs.version }} | ||
|
||
call-publish-release: | ||
needs: call-build | ||
uses: ./.github/workflows/publish-release.yaml | ||
with: | ||
release_version: ${{ inputs.version }} | ||
|
||
cleanup-on-failure: | ||
# Only run cleanup if either call-build or call-publish-release fail. | ||
needs: [call-build, call-publish-release] | ||
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') }} | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.version }} | ||
# Fetch two commits, so you can hard reset below | ||
fetch-depth: 2 | ||
|
||
- name: Cleanup tag and Changelog | ||
run: | | ||
git config user.name "github-bot :robot:" | ||
git config user.email noreply@github.com | ||
git reset --hard HEAD~1 | ||
git push --force origin HEAD:main | ||
git tag -d ${{ inputs.version }} | ||
git push --delete origin ${{ inputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: "Publish Release" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
release_version: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
publish-new-release: | ||
runs-on: ubuntu-22.04 | ||
environment: | ||
name: pypi | ||
url: https://pypi.org/project/markdown2anki/ | ||
permissions: | ||
# IMPORTANT: this permissions are mandatory for trusted publishing with | ||
# OIDC. | ||
id-token: write | ||
contents: write | ||
|
||
steps: | ||
- name: Preprocess version tag | ||
run: | | ||
# This is needed due to the mindsers/changelog-reader-action expecting | ||
# version tag without 'v' prefix. | ||
version_cut=$(echo "${{ inputs.release_version }}" | cut -c 2-) | ||
echo "release_version=${{ inputs.release_version }}" >> $GITHUB_ENV | ||
echo "release_version_cut=$version_cut" >> $GITHUB_ENV | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ env.release_version }} | ||
|
||
- name: Get latest Changelog entry | ||
id: changelog-reader | ||
uses: mindsers/changelog-reader-action@v2.2.2 | ||
with: | ||
version: ${{ env.release_version_cut }} | ||
|
||
- name: Download artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist | ||
|
||
- name: Publish distribution to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
|
||
- name: Publish Release | ||
uses: softprops/action-gh-release@v0.1.15 | ||
with: | ||
files: dist/* | ||
tag_name: ${{ env.release_version }} | ||
body: | | ||
# Release notes | ||
${{ steps.changelog-reader.outputs.changes }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.