Merge pull request #3 from CDCgov/dan/remove-phdi #2
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
name: Create New Release | |
on: | |
workflow_dispatch: | |
push: | |
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 | |
list-containers: | |
needs: check-commit-message | |
if: ${{ needs.check-commit-message.outputs.contains_release == 'true' }} | |
uses: ./.github/workflows/listContainers.yaml | |
test-for-release: | |
needs: | |
- check-commit-message | |
- list-containers | |
if: ${{ needs.check-commit-message.outputs.contains_release == 'true' }} | |
strategy: | |
matrix: | |
container: ${{fromJson(needs.list-containers.outputs.all-containers)}} | |
uses: ./.github/workflows/run-container-workflow.yaml | |
with: | |
container: ${{ matrix.container }} | |
secrets: inherit | |
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: Set environment variable for pdoc | |
run: echo "PDOC_ALLOW_EXEC=1" >> $GITHUB_ENV | |
- name: Clear Poetry Cache | |
run: | | |
poetry cache clear pypi --all | |
poetry cache clear virtualenvs --all | |
- 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 | |
# Create updated container docs for the latest release | |
generate-and-update-container-docs: | |
needs: | |
- tag-release | |
- list-containers | |
- generate-and-update-phdi-docs | |
permissions: | |
contents: write | |
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 Documentation | |
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 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: docs | |
- name: Download phdi docs from artifacts | |
uses: actions/[email protected] | |
with: | |
name: phdi-docs | |
path: ./docs/${{ needs.tag-release.outputs.version }}/sdk | |
- name: Download container docs from artifacts | |
uses: actions/[email protected] | |
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: Commit New Documentation | |
uses: EndBug/add-and-commit@v9 | |
with: | |
add: docs | |
message: Automated update of docs for ${{ needs.tag-release.outputs.version }} release. |