Skip to content

Commit

Permalink
feat: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JossWhittle committed May 23, 2023
1 parent 612fe52 commit 239db6f
Show file tree
Hide file tree
Showing 8 changed files with 802 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Add to Project
on:
issues:
types: [opened, labeled]
pull_request:
types: [opened, labeled]

jobs:
project:
runs-on: [self-hosted, linux, x64]

steps:
- name: generate token
id: generate-token
uses: tibdex/[email protected]
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: add issue or pr to project
uses: actions/[email protected]
with:
project-url: https://github.com/orgs/SwanseaUniversityMedical/projects/6
github-token: ${{ steps.generate-token.outputs.token }}
353 changes: 353 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,353 @@
name: Build and Release Container

on:
push:
paths:
- '.github/workflows/release.yaml'
- 'plugins/**'
- 'containers/**'
- 'charts/**'
branches:
- '**'

env:
HARBOR_REGISTRY: ${{ vars.HARBOR_REGISTRY }}
HARBOR_PROJECT: ${{ vars.HARBOR_PROJECT }}
HARBOR_REPO: ${{ vars.HARBOR_REPO }}
HARBOR_USER: ${{ vars.HARBOR_USER }}
HARBOR_TOKEN: ${{ secrets.HARBOR_TOKEN }}

jobs:
release-jupyter-container:
runs-on: [self-hosted, linux, x64]

env:
TAG_PREFIX: 'DARE-Jupyter-Container'
TAG_FORMAT: 'DARE-Jupyter-Container-${version}'
HARBOR_JUPYTER_REPO: ${{ vars.HARBOR_REPO }}

steps:
- name: clone repo
uses: actions/checkout@v3

- uses: dorny/paths-filter@v2
id: container-changes
with:
filters: |
src:
- '.github/workflows/release.yaml'
- 'containers/jupyter/**'
- 'plugins/**'
- name: build container
if: steps.container-changes.outputs.src == 'true'
run: |
docker build -t image -f "containers/jupyter/Dockerfile" .
- name: registry login
if: steps.container-changes.outputs.src == 'true'
run: |
echo "$HARBOR_TOKEN" | docker login $HARBOR_REGISTRY -u $HARBOR_USER --password-stdin
- name: generate token
if: steps.container-changes.outputs.src == 'true'
id: generate-token
uses: tibdex/[email protected]
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: semantic release dry run
if: steps.container-changes.outputs.src == 'true'
uses: docker://ghcr.io/codfish/semantic-release-action:v2
id: semantic-dry
with:
dry_run: true

branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'main'
]
tag_format: ${{ env.TAG_FORMAT }}

plugins: |-
[
['@semantic-release/commit-analyzer', {
"releaseRules": [
{"type": "major", "release": "major"},
{"type": "minor", "release": "minor"},
{"type": "patch", "release": "patch"},
{"type": "no-release", "release": false},
{"type": "chore", "release": "patch"},
{"type": "refactor", "release": "patch"},
{"type": "style", "release": "patch"},
{"type": "docs", "release": false},
{"type": "test", "release": false},
{"type": "ci", "release": false},
{"type": "feat", "release": "minor"},
{"type": "revert", "release": "patch"},
{"type": "perf", "release": "patch"},
{"type": "fix", "release": "patch"},
{"type": "build", "release": "patch"},
],
}]
]
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

- name: semantic release
if: steps.container-changes.outputs.src == 'true' && steps.semantic-dry.outputs.new-release-published == 'true'
uses: docker://ghcr.io/codfish/semantic-release-action:v2
id: semantic
with:
branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'main'
]
tag_format: ${{ env.TAG_FORMAT }}

additional_packages: |
['@semantic-release/exec']
plugins: |-
[
['@semantic-release/commit-analyzer', {
"releaseRules": [
{"type": "major", "release": "major"},
{"type": "minor", "release": "minor"},
{"type": "patch", "release": "patch"},
{"type": "no-release", "release": false},
{"type": "chore", "release": "patch"},
{"type": "refactor", "release": "patch"},
{"type": "style", "release": "patch"},
{"type": "docs", "release": false},
{"type": "test", "release": false},
{"type": "ci", "release": false},
{"type": "feat", "release": "minor"},
{"type": "revert", "release": "patch"},
{"type": "perf", "release": "patch"},
{"type": "fix", "release": "patch"},
{"type": "build", "release": "patch"},
],
}],
['@semantic-release/exec', {
"generateNotesCmd": "echo '${ process.env.RELEASE_NOTES }'"
}],
'@semantic-release/release-notes-generator',
['@semantic-release/github', {
"successComment": false,
"failTitle": false
}]
]
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
RELEASE_NOTES: |
```
echo "<token>" | docker login ${{ env.HARBOR_REGISTRY }} -u <username> --password-stdin
docker pull ${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.HARBOR_JUPYTER_REPO }}:${{ steps.semantic-dry.outputs.release-version }}
```
- name: container push to registry
id: container-push
if: steps.container-changes.outputs.src == 'true' && steps.semantic.outputs.new-release-published == 'true'
run: |
docker tag image $HARBOR_REGISTRY/$HARBOR_PROJECT/$HARBOR_JUPYTER_REPO:$TAG
docker push $HARBOR_REGISTRY/$HARBOR_PROJECT/$HARBOR_JUPYTER_REPO:$TAG
env:
TAG: ${{ steps.semantic.outputs.release-version }}

- name: delete orphaned release on container push failure
uses: dev-drprasad/[email protected]
if: (failure() && steps.container-push.outcome == 'failure') && steps.semantic.outputs.new-release-published == 'true'
with:
tag_name: ${ env.TAG_PREFIX }-${{ steps.semantic.outputs.release-version }}
delete_release: true
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

release-chart:
needs: release-jupyter-container
runs-on: [ self-hosted, linux, x64 ]

env:
TAG_PREFIX: 'DARE-Jupyter-Helm'
TAG_FORMAT: 'DARE-Jupyter-Helm-${version}'

steps:
- name: clone repo
uses: actions/checkout@v3

- uses: dorny/paths-filter@v2
id: chart-changes
with:
filters: |
src:
- '.github/workflows/release.yaml'
- 'charts/**'
- name: generate token
if: steps.chart-changes.outputs.src == 'true'
id: generate-token
uses: tibdex/[email protected]
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: install helm
if: steps.chart-changes.outputs.src == 'true'
uses: azure/setup-helm@v3
with:
version: 'latest'
token: ${{ steps.generate-token.outputs.token }}

- name: semantic release dry run
if: steps.chart-changes.outputs.src == 'true'
uses: docker://ghcr.io/codfish/semantic-release-action:v2
id: semantic-dry
with:
dry_run: true

branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'main'
]
tag_format: ${{ env.TAG_FORMAT }}

plugins: |-
[
['@semantic-release/commit-analyzer', {
"releaseRules": [
{"type": "major", "release": "major"},
{"type": "minor", "release": "minor"},
{"type": "patch", "release": "patch"},
{"type": "no-release", "release": false},
{"type": "chore", "release": "patch"},
{"type": "refactor", "release": "patch"},
{"type": "style", "release": "patch"},
{"type": "docs", "release": false},
{"type": "test", "release": false},
{"type": "ci", "release": false},
{"type": "feat", "release": "minor"},
{"type": "revert", "release": "patch"},
{"type": "perf", "release": "patch"},
{"type": "fix", "release": "patch"},
{"type": "build", "release": "patch"},
],
}]
]
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

- name: helm package
if: steps.chart-changes.outputs.src == 'true' && steps.semantic-dry.outputs.new-release-published == 'true'
run: |
set -x
helm package ./charts/$HARBOR_REPO -d . --version $TAG --app-version $TAG
tar -xzf $(echo *.tgz) -C ./charts $HARBOR_REPO/Chart.yaml
env:
TAG: ${{ steps.semantic-dry.outputs.release-version }}

- name: semantic release
if: steps.chart-changes.outputs.src == 'true' && steps.semantic-dry.outputs.new-release-published == 'true'
uses: docker://ghcr.io/codfish/semantic-release-action:v2
id: semantic
with:
branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'main'
]
tag_format: ${{ env.TAG_FORMAT }}

additional_packages: |
['@semantic-release/exec', '@semantic-release/git']
plugins: |-
[
['@semantic-release/commit-analyzer', {
"releaseRules": [
{"type": "major", "release": "major"},
{"type": "minor", "release": "minor"},
{"type": "patch", "release": "patch"},
{"type": "no-release", "release": false},
{"type": "chore", "release": "patch"},
{"type": "refactor", "release": "patch"},
{"type": "style", "release": "patch"},
{"type": "docs", "release": false},
{"type": "test", "release": false},
{"type": "ci", "release": false},
{"type": "feat", "release": "minor"},
{"type": "revert", "release": "patch"},
{"type": "perf", "release": "patch"},
{"type": "fix", "release": "patch"},
{"type": "build", "release": "patch"},
],
}],
['@semantic-release/exec', {
"generateNotesCmd": "echo '${ process.env.RELEASE_NOTES }'"
}],
'@semantic-release/release-notes-generator',
['@semantic-release/git', {
"assets": ["./charts/**"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}],
['@semantic-release/github', {
"successComment": false,
"failTitle": false
}]
]
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
RELEASE_NOTES: |
```
helm repo add --pass-credentials --username <username> --password <password> <repo> https://${{ env.HARBOR_REGISTRY }}/chartrepo/${{ env.HARBOR_PROJECT }}
helm pull --version ${{ steps.semantic-dry.outputs.release-version }} <repo>/${{ env.HARBOR_REPO }}
ls *.tgz
# ${{ env.HARBOR_REPO }}-${{ steps.semantic-dry.outputs.release-version }}.tgz
```
- name: helm push to registry
id: chart-push
if: steps.chart-changes.outputs.src == 'true' && steps.semantic.outputs.new-release-published == 'true'
run: |
set -x
helm plugin install https://github.com/chartmuseum/helm-push
helm repo add --pass-credentials --username "$HARBOR_USER" --password "$HARBOR_TOKEN" harbor https://$HARBOR_REGISTRY/chartrepo/$HARBOR_PROJECT
helm cm-push $(echo *.tgz) harbor
sleep 2
helm repo update
helm pull harbor/$HARBOR_REPO --version $TAG
env:
TAG: ${{ steps.semantic.outputs.release-version }}

- name: delete orphaned release on chart push failure
uses: dev-drprasad/[email protected]
if: (failure() && steps.chart-push.outcome == 'failure') && steps.semantic.outputs.new-release-published == 'true'
with:
tag_name: ${ env.TAG_PREFIX }-${{ steps.semantic.outputs.release-version }}
delete_release: true
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
Loading

0 comments on commit 239db6f

Please sign in to comment.