Skip to content

release: v1.6.1 (#737) #188

release: v1.6.1 (#737)

release: v1.6.1 (#737) #188

Workflow file for this run

name: Release
on:
pull_request:
paths: [internal/version/version.go]
push:
branches: [main]
paths: [internal/version/version.go]
release:
types: [published]
permissions: read-all
jobs:
validate:
if: github.event_name != 'release'
name: Validate Release
runs-on: ubuntu-latest
permissions:
contents: write # To be able to create draft releases
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
- name: Setup go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v5
with:
go-version: stable
cache-dependency-path: '**/go.mod'
# Obtains the current configured version tag from source, and verifies it is a valid tag name.
# Also checks whether the tag already exists.
- name: Determine version
id: version
run: |-
set -euo pipefail
# From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string, with added v prefix.
VERSION_TAG_REGEX='^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-((0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'
version=$(grep -E "${VERSION_TAG_REGEX}" <(go run . version -static | cut -d' ' -f 2))
echo "tag=${version}" >> "${GITHUB_OUTPUT}"
if gh release view "${version}" --json isDraft; then
echo "exists=true" >> "${GITHUB_OUTPUT}"
else
echo "exists=false" >> "${GITHUB_OUTPUT}"
fi
env:
GH_TOKEN: ${{ github.token }}
# If this is a pull request, and the release does not yet exist, the PR title must be "release: <tag>"
- name: 'Pull Request title must be "release: ${{ steps.version.outputs.tag }}"'
if: "github.event_name == 'pull_request' && !fromJSON(steps.version.outputs.exists) && format('release: {0}', steps.version.outputs.tag) != github.event.pull_request.title"
run: |-
echo "Please update the PR title to \"release: ${{ steps.version.outputs.tag }}\" (instead of ${EVENT_PR_TITLE})"
exit 1
env:
EVENT_PR_TITLE: ${{ toJSON(github.event.pull_request.title) }}
# Release must not already exist (if the PR title suggests this is intended to be a release)
- name: Release ${{ steps.version.outputs.tag }} already exists
if: github.event_name == 'pull_request' && fromJSON(steps.version.outputs.exists) && startsWith(github.event.pull_request.title, 'release:')
run: |-
echo 'A release already exists for tag ${{ steps.version.outputs.tag }}. Please update to another version.'
exit 1
# If the release does not yet exist, create a draft release targeting this commit.
- name: Create draft release
if: github.event_name == 'push' && steps.version.outputs.exists == 'false'
# We explicitly set the notes start tag because GitHub otherwise does not make the right
# decision (it is very sensitive to non-version tags being present in the repository, and
# the Go nexted modules tags hinder it). We pick the latest non-prerelease tag as the start
# tag, always.
run: |-
lastTag=$(gh release list \
--exclude-drafts \
--exclude-pre-releases \
--limit=1 \
--json=tagName \
--template="{{ (index . 0).tagName }}" \
)
gh release create '${{ steps.version.outputs.tag }}' \
--draft \
--generate-notes \
--target='${{ github.sha }}' \
--title='${{ steps.version.outputs.tag }}' \
--notes-start-tag="${lastTag}" \
${{ contains(steps.version.outputs.tag, '-') && '--prerelease' || '' }}
env:
GH_TOKEN: ${{ github.token }}
release:
if: github.event_name == 'release'
name: Tag Release
runs-on: ubuntu-latest
permissions:
contents: write # To be able to create new tags
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
with:
ref: ${{ github.event.release.target_commitish }}
- name: Setup go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v5
with:
go-version: oldstable
cache-dependency-path: '**/go.mod'
- name: Configure git
env:
AUTHOR_NAME: ${{ github.event.release.author.name || 'Github Actions' }}
AUTHOR_EMAIL: ${{ github.event.release.author.email || '[email protected]' }}
run: |-
git config --global user.name "${AUTHOR_NAME}"
git config --global user.email "${AUTHOR_EMAIL}"
- name: Tag all submodules
env:
EVENT_TAG: ${{ github.event.release.tag_name }}
run: |-
find . -iname go.mod -not -path '*/_*' -print0 | while IFS= read -r -d '' gomod; do
dir=$(dirname "${gomod}")
mod=$(go -C "${dir}" list -m)
case "${mod}" in
github.com/DataDog/orchestrion)
# This is the main module, the release already tagged it
continue
;;
github.com/DataDog/orchestrion/*)
# This is a submodule, we'll publish it if the prefix matches the directory name
echo "Found sub-module: ${mod} in ${gomod}"
suffix="${mod#'github.com/DataDog/orchestrion/'}"
if [ "${suffix}" != "${dir#'./'}" ]; then
echo "-> Ignoring submodule with mismatched directory path and suffix: ${dir#'./'} != ${suffix}"
continue
fi
tag="${suffix}/${EVENT_TAG}"
echo "-> Adding required submodule tag: ${tag}"
git tag -m "${EVENT_TAG}" "${tag}"
git push origin "${tag}"
;;
*)
# This is not a submodule, we'll skip it
echo "-> Ignorning non-submodule: ${mod} in ${gomod}"
;;
esac
done