Skip to content

Commit

Permalink
WIP Separate release drafting from publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Feb 6, 2024
1 parent 8a939a4 commit 35559da
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 59 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/draft_releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Draft releases

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

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# Freely interrupt release drafting workflows, they do not depend on each other and always generate the full release based on the previous one
cancel-in-progress: true

jobs:
draft-release:
name: "Draft ${{ matrix.app }} release"
runs-on: ubuntu-latest
permissions:
# write permission is required to create a github release
contents: write

strategy:
matrix:
app:
- api
- frontend
- catalog
- ingestion_server

steps:
- uses: actions/checkout@v4

- uses: release-drafter/release-drafter@v5
id: release-drafter
with:
config-name: release-drafter-${{ matrix.app }}.yml
version: ${{ matrix.app }}-draft
tag: ${{ matrix.app }}-draft
name: "TESTING ${{ matrix.app }}-draft"
draft: true
commitish: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90 changes: 31 additions & 59 deletions .github/workflows/release-app.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
name: Release app

on:
workflow_dispatch:
inputs:
app:
type: choice
options:
- api
- ingestion_server
- frontend
- catalog
required: true
description: Application to release. If `api` or `frontend`, the deployment workflow will automatically be dispatched for you.
image-sha:
type: string
required: true
description: The SHA of the staging image to tag.

concurrency: ${{ github.workflow }}-${{ inputs.app }}
release:

# The app-name expression is duplicated between here and `env` below because neither context is able to reference the other
# but both need it
concurrency: >
${{ github.workflow }}-
${{
startsWith(github.ref_name, 'api-') && 'api'
|| startsWith(github.ref_name, 'ingestion_server-') && 'ingestion_server'
|| startsWith(github.ref_name, 'catalog-') && 'catalog'
|| startsWith(github.ref_name, 'frontend-') && 'frontend'
}}
jobs:
release-app:
Expand All @@ -30,43 +25,20 @@ jobs:
packages: write
# Needed to open the changelog PR
pull-requests: write
env:
APP_NAME: >
${{
startsWith(github.ref_name, 'api-') && 'api'
|| startsWith(github.ref_name, 'ingestion_server-') && 'ingestion_server'
|| startsWith(github.ref_name, 'catalog-') && 'catalog'
|| startsWith(github.ref_name, 'frontend-') && 'frontend'
}}
steps:
- uses: actions/checkout@v4
with:
# Creating the tag requires having the whole history of `main`
fetch-depth: 0

- name: Validate `sha-tag` input
uses: actions/github-script@v6
with:
script: |
let exists = undefined,
page = 0
while (!exists) {
page += 1
const { data: versions } =
await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
package_type: 'container',
// We do not have to validate that auxiliary images also exist as they're built at the same time
// as the "main" image. e.g., `api_nginx` is always built when `api` is built and they'll have
// the same set of tags.
package_name: 'openverse-${{ inputs.app }}',
org: 'WordPress',
page,
// max of `per_page`
per_page: 100,
})
if (!versions.length) {
break
}
exists = versions.some((v) => v.metadata.container.tags.includes('${{ inputs.image-sha }}'))
}
if (!exists) {
throw new Error(
`'${{ inputs.image-sha }}' does not appear to be a valid SHA tag for ${{ inputs.app }}.`
)
}
- name: Calculate tag name
id: tag
run: |
Expand All @@ -77,7 +49,7 @@ jobs:
# Split image and git tag to avoid app name duplicated in the fully qualified image name
{
echo "date=$formatted_date";
echo "git-tag=${{ inputs.app }}-$formatted_date";
echo "git-tag=${{ env.APP_NAME }}-$formatted_date";
echo "image-tag=rel-$formatted_date";
} >> "$GITHUB_OUTPUT"
Expand All @@ -90,20 +62,20 @@ jobs:

- name: Add new tag to existing docker image
run: |
docker buildx imagetools create ghcr.io/wordpress/openverse-${{ inputs.app }}:${{ inputs.image-sha }} --tag ghcr.io/wordpress/openverse-${{ inputs.app }}:${{ steps.tag.outputs.image-tag }}
docker buildx imagetools create ghcr.io/wordpress/openverse-${{ env.APP_NAME }}:latest --tag ghcr.io/wordpress/openverse-${{ env.APP_NAME }}:${{ steps.tag.outputs.image-tag }}
if [[ "${{ inputs.app }}" == "api" ]] || [[ "${{ inputs.app }}" == "frontend" ]]; then
docker buildx imagetools create ghcr.io/wordpress/openverse-${{ inputs.app }}_nginx:${{ inputs.image-sha }} --tag ghcr.io/wordpress/openverse-${{ inputs.app }}_nginx:${{ steps.tag.outputs.image-tag }}
if [[ "${{ env.APP_NAME }}" == "api" ]] || [[ "${{ env.APP_NAME }}" == "frontend" ]]; then
docker buildx imagetools create ghcr.io/wordpress/openverse-${{ env.APP_NAME }}_nginx:latest --tag ghcr.io/wordpress/openverse-${{ env.APP_NAME }}_nginx:${{ steps.tag.outputs.image-tag }}
fi
- name: Deploy production application
if: inputs.app == 'frontend' || inputs.app == 'api'
if: env.APP_NAME == 'frontend' || env.APP_NAME == 'api'
uses: felixp8/[email protected]
with:
owner: WordPress
repo: openverse-infrastructure
token: ${{ secrets.ACCESS_TOKEN }}
event_type: deploy_production_${{ inputs.app == 'frontend' && 'nuxt' || inputs.app }}
event_type: deploy_production_${{ env.APP_NAME == 'frontend' && 'nuxt' || env.APP_NAME }}
client_payload: |
{
"actor": "${{ github.actor }}",
Expand All @@ -118,11 +90,11 @@ jobs:
# minutes is reached. On the other hand, we do want to wait
# so that there is a record of the successful deployment.

- name: Create and publish release
- name: Publish release
uses: release-drafter/release-drafter@v5
id: release-drafter
with:
config-name: release-drafter-${{ inputs.app }}.yml
config-name: release-drafter-${{ env.APP_NAME }}.yml
version: ${{ steps.tag.outputs.date }}
tag: ${{ steps.tag.outputs.git-tag }}
name: ${{ steps.tag.outputs.git-tag }}
Expand All @@ -133,7 +105,7 @@ jobs:

- name: Add new changelog file to documentation
env:
APP: ${{ inputs.app }}
APP: ${{ env.APP_NAME }}
DATE: ${{ steps.tag.outputs.date }}
RELEASE_BODY: ${{ steps.release-drafter.outputs.body }}
working-directory: automations/python/workflows
Expand All @@ -156,7 +128,7 @@ jobs:
- name: Lint the changelog file so that it passes CI
run: |
# Add the new changelog file to git so that pre-commit can lint it.
git add documentation/changelogs/${{ inputs.app }}/${{ steps.tag.outputs.date }}.md
git add documentation/changelogs/${{ env.APP_NAME }}/${{ steps.tag.outputs.date }}.md
just precommit
# Ensure this step passes even if linting has made changes so the workflow can continue
just lint || true
Expand All @@ -173,7 +145,7 @@ jobs:
title: Publish changelog for ${{ steps.tag.outputs.git-tag }}
# Add labels to pass CI
labels: |
🧱 stack: ${{ inputs.app == 'ingestion_server' && 'ingestion server' || inputs.app }}
🧱 stack: ${{ env.APP_NAME == 'ingestion_server' && 'ingestion server' || env.APP_NAME }}
🌟 goal: addition
📄 aspect: text
🟩 priority: low
Expand Down

0 comments on commit 35559da

Please sign in to comment.