api-2025.01.11.11.22.59 #58
Workflow file for this run
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: Tag Docker image and trigger deployment | |
on: | |
release: | |
types: [released] | |
# Prevent concurrency with other workflows in the "Release workflow group" | |
# See https://github.com/WordPress/openverse/issues/4505 for context | |
concurrency: | |
group: operates_on_github_releases | |
cancel-in-progress: false | |
jobs: | |
tag-docker-image-and-trigger-deployment: | |
name: Release app | |
runs-on: ubuntu-latest | |
# Prevent running this workflow on forks, it's unnecessary for external contributors | |
if: github.repository_owner == 'WordPress' | |
permissions: | |
# Needed to create the GitHub release on the repo | |
contents: write | |
# Needed for pushing the new docker image tag | |
packages: write | |
# Needed to open the changelog PR | |
pull-requests: write | |
env: | |
# Do not split this into multiple lines, it will not work: | |
# https://github.com/WordPress/openverse/pull/3789#pullrequestreview-1876525552 | |
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: Calculate tag name | |
id: tag | |
run: | | |
release_date=$(echo '${{ github.ref_name }}' | sed 's/${{ env.APP_NAME }}-//') | |
# Generate `rel-` prefixed image tag to avoid duplicated app name between image and tag | |
{ | |
echo "date=$release_date"; | |
echo "image-tag=rel-$release_date"; | |
} >> "$GITHUB_OUTPUT" | |
- name: Log in to GitHub Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: https://ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Tag latest with release tag | |
run: | | |
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 [[ "${{ 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: env.APP_NAME == 'frontend' || env.APP_NAME == 'api' | |
uses: felixp8/dispatch-and-wait@v0.1.0 | |
with: | |
owner: WordPress | |
repo: openverse-infrastructure | |
token: ${{ secrets.ACCESS_TOKEN }} | |
event_type: deploy_production_${{ env.APP_NAME == 'frontend' && 'nuxt' || env.APP_NAME }} | |
client_payload: | | |
{ | |
"actor": "${{ github.actor }}", | |
"tag": "${{ steps.tag.outputs.image-tag }}" | |
} | |
wait_time: 60 # check every minute | |
max_time: 1800 # allow up to 30 minutes for a deployment | |
# max_time can't easily be configured per application | |
# without duplicating information between our infrastructure | |
# and this workflow. The upstream workflows already have | |
# timeouts appropriately configured and will all fail before 30 | |
# minutes is reached. On the other hand, we do want to wait | |
# so that there is a record of the successful deployment. | |
- name: Add new changelog file to documentation | |
env: | |
APP: ${{ env.APP_NAME }} | |
DATE: ${{ steps.tag.outputs.date }} | |
RELEASE_BODY: ${{ github.event.release.body }} | |
working-directory: automations/python/workflows | |
run: python write_changelog.py | |
- name: Setup CI env | |
uses: ./.github/actions/setup-env | |
with: | |
# PDM is needed to run Vale | |
setup_python: "true" | |
# Node.js is needed by lint actions. | |
install_recipe: "node-install" | |
- name: Cache pre-commit envs | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pre-commit | |
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} | |
- 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/${{ 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 | |
- name: Open changelog PR | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
# Access token necessary for PRs to run with CI | |
token: ${{ secrets.ACCESS_TOKEN }} | |
base: main | |
branch: changelog/${{ github.ref_name }} | |
commit-message: Publish changelog for ${{ github.ref_name }} | |
title: Publish changelog for ${{ github.ref_name }} | |
# Add labels to pass CI | |
labels: | | |
🧱 stack: ${{ env.APP_NAME == 'ingestion_server' && 'ingestion server' || env.APP_NAME }} | |
🌟 goal: addition | |
📄 aspect: text | |
🟩 priority: low | |
skip-changelog | |
body: | | |
This changelog PR was automatically generated for @${{ github.actor }} as a result of the ${{ github.workflow }} workflow. |