v0.54.10 #1171
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: 'openapi-ws release-v2' | |
on: | |
workflow_dispatch: {} | |
release: | |
types: | |
- published | |
env: | |
SKIP_ANNOUNCE: 'false' | |
SKIP_PUBLISH: 'false' | |
jobs: | |
verify-prerelease-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Verify prerelease has a prerelease tag | |
if: github.event.release.prerelease | |
run: | | |
if ! [[ "${{ github.event.release.tag_name }}" =~ ^v[0-9]+.[0-9]+.[0-9]+\-.+ ]] | |
then | |
echo "ERROR: '${{ github.event.release.tag_name }}' is not a valid prerelease tag" | |
exit 1 | |
fi | |
verify-versions-agree: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Confirm GH release and package.json agree on version | |
if: github.event_name == 'release' | |
run: | | |
# add a 'v' prefix to match the Git tag | |
package_version=v$(jq -r '.version' < package.json) | |
if [ "${package_version}" != "${{ github.event.release.tag_name }}" ] | |
then | |
echo "ERROR: package.json version (${package_version}) does not match GitHub release tag (${{ github.event.release.tag_name }})" | |
exit 1 | |
fi | |
- name: Confirm all package.json files have the same version | |
run: .github/scripts/version-sync | |
verify-version-unpublished: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Confirm release version is unpublished | |
run: | | |
package_version=$(jq -r '.version' < package.json) | |
is_published=$( | |
yarn npm info "@useoptic/openapi-utilities" --json \ | |
| jq -rs '.[0]' \ | |
| jq ".versions // []" \ | |
| jq -r "any(.[]; . == \"$package_version\")" | |
) | |
if [ "${is_published}" == "true" ] | |
then | |
echo "ERROR: @useoptic/openapi-utilities@$package_version is already published" | |
exit 1 | |
fi | |
release: | |
runs-on: ubuntu-latest-16-core | |
needs: | |
- verify-prerelease-tag | |
- verify-versions-agree | |
- verify-version-unpublished | |
outputs: | |
optic_version: ${{ steps.version.outputs.optic_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
cache: yarn | |
- name: Install Task | |
run: curl -sL https://taskfile.dev/install.sh | sudo bash -s -- -b /usr/local/bin/ | |
- name: Build | |
env: | |
NODE_ENV: production | |
run: | | |
set -a | |
source projects/optic/.env.production | |
task default | |
- name: Test | |
run: task test | |
- name: Set NPM credentials | |
run: yarn config set 'npmScopes.useoptic.npmAuthToken' "${{ secrets.PUBLISH_NPM_OPTIC_BOT }}" | |
- name: Set release channel to 'prerelease' | |
run: echo "RELEASE_CHANNEL=prerelease" >> $GITHUB_ENV | |
- name: Set release channel to 'latest' | |
if: github.event_name == 'release' | |
run: | | |
if [[ "${{ github.event.release.prerelease }}" == "false" ]] | |
then | |
echo "Setting RELEASE_CHANNEL to 'latest'" | |
echo "RELEASE_CHANNEL=latest" >> $GITHUB_ENV | |
else | |
echo "Leaving RELEASE_CHANNEL as '$RELEASE_CHANNEL'" | |
fi | |
- name: Get package version | |
id: version | |
run: | | |
v=$(jq -r .version < package.json) | |
echo "VERSION=$v" >> $GITHUB_ENV | |
echo "optic_version=v${v}" >> $GITHUB_OUTPUT | |
- name: Publish NPM | |
run: | | |
if [ "$SKIP_PUBLISH" = "false" ] | |
then | |
echo "Publishing $VERSION to the "$RELEASE_CHANNEL" channel" | |
cp README.md ./projects/optic/README.md | |
task publish -- --tag $RELEASE_CHANNEL | |
else | |
echo "SKIP_PUBLISH=$SKIP_PUBLISH" | |
echo "Would publish $VERSION to the "$RELEASE_CHANNEL" channel" | |
fi | |
- name: Announce success | |
uses: slackapi/[email protected] | |
if: > | |
success() | |
&& env.SKIP_ANNOUNCE == 'false' | |
&& env.SKIP_PUBLISH == 'false' | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.BUILD_BOT_SLACK_WEBHOOK_URL_RELEASES }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | |
with: | |
payload: | | |
{ | |
"text": "${{github.actor}}: ✅ optic v${{env.VERSION}} packages published to channel `${{env.RELEASE_CHANNEL}}`!" | |
} | |
- name: Announce failure | |
uses: slackapi/[email protected] | |
if: > | |
failure() | |
&& env.SKIP_ANNOUNCE == 'false' | |
&& env.SKIP_PUBLISH == 'false' | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.BUILD_BOT_SLACK_WEBHOOK_URL_RELEASES }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | |
with: | |
payload: | | |
{ | |
"text": "${{github.actor}}: 🚫 optic v${{env.VERSION}} failed to publish." | |
} | |
publish-binaries: | |
needs: release | |
uses: ./.github/workflows/release-binaries.yml | |
with: | |
release_tag_name: ${{ github.event.release.tag_name }} | |
secrets: inherit | |
publish-container-image: | |
needs: | |
- release | |
- publish-binaries | |
if: github.event.release.prerelease == false | |
uses: ./.github/workflows/release-container-image.yml | |
with: | |
optic_version: ${{ needs.release.outputs.optic_version }} | |
secrets: inherit | |