Skip to content

Commit

Permalink
setup octopus releases
Browse files Browse the repository at this point in the history
  • Loading branch information
alismx committed May 3, 2024
1 parent 1fe7b86 commit 3766505
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 257 deletions.
272 changes: 15 additions & 257 deletions .github/workflows/createNewRelease.yaml
Original file line number Diff line number Diff line change
@@ -1,267 +1,25 @@
name: Create New Release
name: Octopus

on:
push:
branches:
- main
pull_request:
branches:
- main

# Run all tests before making a release
jobs:
# Only make a release if commit contains [RELEASE]
check-commit-message:
runs-on: ubuntu-latest
outputs:
contains_release: ${{ steps.commit_check.outputs.contains_release }}
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Check commit message for [RELEASE]
id: commit_check
run: |
if [[ "${{ github.event.head_commit.message }}" == *"[RELEASE]"* ]]; then
echo "contains_release=true" >> $GITHUB_OUTPUT
else
echo "contains_release=false" >> $GITHUB_OUTPUT
fi
test-for-release:
needs: check-commit-message
if: ${{ needs.check-commit-message.outputs.contains_release == 'true' }}
uses: ./.github/workflows/test.yaml
tag-release:
name: Update phdi init version number
needs: test-for-release
permissions:
contents: write
outputs:
version: ${{ steps.get_version.outputs.version }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: "main"
- name: Install poetry and dependencies
run: |
pip install poetry
# update the version number in the phdi/__init.py__ file
- name: Get PHDI Version
id: get_version
run: |
VERSION_WITH_PHDI=$(poetry version)
echo "version=${VERSION_WITH_PHDI:5}" >> $GITHUB_OUTPUT
# Create new release tag
- name: Set up Git user
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Tag Release
uses: EndBug/latest-tag@latest
with:
ref: ${{ steps.get_version.outputs.version }}
# Generate release notes
- name: Generate release notes
id: release_notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest_release_date=$(gh api "/repos/$GITHUB_REPOSITORY/releases?per_page=1" | jq ".[0].created_at")
prs=$(gh pr list --base main --state closed --json title,number,url,closedAt -q ".[] | select(.closedAt > $latest_release_date) | select(.title | contains(\"RELEASE\") | not)")
echo "# Release Notes" > release-notes.md
echo "" >> release-notes.md
echo "" >> release-notes.md
while IFS= read -r pr; do
pr_title=$(echo "$pr" | jq -r ".title")
pr_number=$(echo "$pr" | jq -r ".number")
pr_url=$(echo "$pr" | jq -r ".url")
line_text="- $pr_title ([#$pr_number]($pr_url))"
echo $line_text >> release-notes.md
done < <(printf '%s' "$prs")
# Create new release based upon the latest created tag
- name: Create Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: ${{ steps.get_version.outputs.version }}
body_path: release-notes.md

release-to-pypi:
name: Build and publish PHDI to PyPI
needs: tag-release
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: ${{ needs.tag-release.outputs.version }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution πŸ“¦ to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

# Rebuild all containers for the new release
build-containers-for-release:
needs:
- tag-release
- release-to-pypi
permissions:
contents: read
packages: write
id-token: write
uses: ./.github/workflows/buildReleaseContainers.yaml
with:
container-tag: ${{ needs.tag-release.outputs.version }}

# Create updated PHDI docs for the latest release
generate-and-update-phdi-docs:
needs:
- tag-release
- build-containers-for-release
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: ${{ needs.tag-release.outputs.version }}

- name: Install poetry and dependencies
run: |
pip install poetry
poetry install
- name: Generate docs and move to docs branch
run: |
poetry run pdoc ./phdi -o ./docs/${{ needs.tag-release.outputs.version }}/sdk
- uses: actions/upload-artifact@v3
with:
name: phdi-docs
path: ./docs/${{ needs.tag-release.outputs.version }}/sdk
env:
OCTOPUS_SPACE: 'default'

# Create updated container docs for the latest release
list-containers:
needs: check-commit-message
if: ${{ needs.check-commit-message.outputs.contains_release == 'true' }}
uses: ./.github/workflows/listContainers.yaml
generate-and-update-container-docs:
needs:
- tag-release
- list-containers
- generate-and-update-phdi-docs
permissions:
contents: write
jobs:
setup:
runs-on: ubuntu-latest
services:
test-db:
image: postgres:13-alpine3.16
env:
POSTGRES_PASSWORD: pw
POSTGRES_DB: testdb
POSTGRES_USER: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name testdb
ports:
- 5432:5432
strategy:
matrix:
container: ${{fromJson(needs.list-containers.outputs.python-containers)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: ${{ needs.tag-release.outputs.version }}

- name: Update Container Documenation
env:
MPI_DBNAME: testdb
MPI_PASSWORD: pw
MPI_DB_TYPE: postgres
MPI_HOST: localhost
MPI_USER: postgres
MPI_PORT: 5432
MPI_PATIENT_TABLE: patient
MPI_PERSON_TABLE: person
run: |
npm i -g redoc-cli
CONTAINER=${{ matrix.container }}
cd $GITHUB_WORKSPACE/containers/$CONTAINER
cp $GITHUB_WORKSPACE/utils/make_openapi_json.py .
pip install -r requirements.txt
python make_openapi_json.py
redoc-cli build -o $GITHUB_WORKSPACE/docs/${{ needs.tag-release.outputs.version }}/containers/$CONTAINER.html openapi.json
- uses: actions/upload-artifact@v3
with:
name: container-docs
path: ./docs/${{ needs.tag-release.outputs.version }}/containers

commit-docs:
needs:
- tag-release
- generate-and-update-phdi-docs
- generate-and-update-container-docs
permissions:
contents: write
runs-on: ubuntu-latest
id-token: write # Required for authentication
steps:
- uses: actions/checkout@v4
with:
ref: docs

- name: Download phdi docs from artifacts
uses: actions/download-artifact@v2
with:
name: phdi-docs
path: ./docs/${{ needs.tag-release.outputs.version }}/sdk

- name: Download container docs from artifacts
uses: actions/download-artifact@v2
with:
name: container-docs
path: ./docs/${{ needs.tag-release.outputs.version }}/containers

- name: Copy to latest folder
run: |
rm -rf ./docs/latest
mkdir -p ./docs/latest/sdk
mkdir -p ./docs/latest/containers
cp -r ./docs/${{ needs.tag-release.outputs.version }}/sdk/* ./docs/latest/sdk
cp -r ./docs/${{ needs.tag-release.outputs.version }}/containers/* ./docs/latest/containers
- name: Login to Octopus πŸ™
uses: OctopusDeploy/login@v1
with:
server: ${{ secrets.OCTOPUS_URL }}
service_account_id: ${{ secrets.OCTOPUS_SERVICE_ACCOUNT_ID }}

- name: Commit New Documentation
uses: EndBug/add-and-commit@v9
with:
add: docs
message: Automated update of docs for ${{ needs.tag-release.outputs.version }} release.
77 changes: 77 additions & 0 deletions .github/workflows/octopusRelease.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Octopus

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
OCTOPUS_SPACE: 'Default'
OCTOPUS_PROJECT: 'Data Ingestion Building Blocks'

jobs:
release-version:
permissions:
contents: write
outputs:
version: ${{ steps.get_version.outputs.version }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: "main"
- name: Install poetry and dependencies
run: pip install poetry
# update the version number in the phdi/__init.py__ file
- name: Get PHDI Version
id: get_version
run: |
VERSION_WITH_PHDI=$(poetry version)
echo "version=${VERSION_WITH_PHDI:5}" >> $GITHUB_OUTPUT
octopus-release:
runs-on: ubuntu-latest
needs: release-version
permissions:
id-token: write # Required for authentication
outputs:
release_number: ${{ steps.create_release.outputs.release_number }}
steps:
- name: Login to Octopus πŸ™
uses: OctopusDeploy/login@v1
with:
server: ${{ secrets.OCTOPUS_URL }}
service_account_id: ${{ secrets.OCTOPUS_SERVICE_ACCOUNT_ID }}

- name: Create a release in Octopus πŸ™
uses: OctopusDeploy/create-release-action@v3
id: create_release
with:
project: ${{ env.OCTOPUS_PROJECT }}
channel: "Channel alis/46"
package_version: ${{ needs.release-version.outputs.version }}

octopus-deployments:
runs-on: ubuntu-latest
needs: octopus-release
permissions:
id-token: write # Required for authentication

steps:
- name: Login to Octopus πŸ™
uses: OctopusDeploy/login@v1
with:
server: ${{ secrets.OCTOPUS_URL }}
service_account_id: ${{ secrets.OCTOPUS_SERVICE_ACCOUNT_ID }}

- name: Deploy a release in Octopus Deploy πŸ™
uses: OctopusDeploy/deploy-release-action@v3
with:
project: ${{ env.OCTOPUS_PROJECT }}
release_number: ${{ needs.octopus-release.outputs.release_number }}
tenant: CDC EXT
environments: Development

0 comments on commit 3766505

Please sign in to comment.