Skip to content

feat: adding subject to AS spec #18

feat: adding subject to AS spec

feat: adding subject to AS spec #18

name: Validate & Release OpenAPI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint-openapi:
runs-on: ubuntu-latest
outputs:
specsChanged: ${{ steps.lint-openapi.outputs.SPECS_CHANGED }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v2
- uses: pnpm/action-setup@v3
- name: Validate OpenAPI specs
id: lint-openapi
run: |
if [[ "$GITHUB_REF_NAME" == "main" ]]; then
BASE_COMMIT="HEAD^"
else
BASE_COMMIT="origin/main"
fi
if git diff --quiet "$BASE_COMMIT" -- openapi/; then
echo "No OpenAPI spec changes detected. Exiting."
echo "SPECS_CHANGED=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "SPECS_CHANGED=true" >> $GITHUB_OUTPUT
echo "Installing dependencies..."
pnpm install --frozen-lockfile
echo "Running OpenAPI lint..."
pnpm lint:openapi
validate-version:
runs-on: ubuntu-latest
needs: [lint-openapi]
if: needs.lint-openapi.outputs.specsChanged == 'true'
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
- uses: actions/setup-node@v2
- uses: pnpm/action-setup@v3
- name: Validate API version
run: |
input_version=$(<VERSION)
read input_major input_minor input_patch <<< $(echo "$input_version" | awk -F'[.v-]' '{print $1, $2, $3}')
# Check if patch version is properly incremented
patch_version_search="v$input_major.$input_minor.*"
latest_version=$(git tag -l $patch_version_search --sort=-taggerdate | head -n 1)
if [ -n "$latest_version" ]; then
read major minor patch <<< $(echo "$latest_version" | awk -F'[.v-]' '{print $1, $2, $3}')
expected_patch=$((patch + 1))
if [ "$input_patch" != "$expected_patch" ]; then
echo "Updating patch version failed: expected ${major}.${minor}.${expected_patch}, got ${input_version}"
exit 1
fi
else
# Check if minor version is properly incremented
minor_version_search="v$input_major.*"
latest_version=$(git tag -l $minor_version_search --sort=-taggerdate | head -n 1)
if [ -n "$latest_version" ]; then
read major minor <<< $(echo "$latest_version" | awk -F'[.v-]' '{print $1, $2}')
expected_minor=$((minor + 1))
expected_patch="0"
if [ "$input_minor" != "$expected_minor" ]; then
echo "Updating minor version failed, expected ${major}.${expected_minor}.${expected_patch}, got ${input_version}"
exit 1
elif [ "$input_patch" != "$expected_patch" ]; then
echo "Updating minor version failed, expected ${major}.${expected_minor}.${expected_patch}, got ${input_version}"
fi
fi
fi
- name: Validate API version across specs
run: |
expected_version=$(<VERSION)
files=(openapi/*.yaml)
all_match=true
for file in "${files[@]}"; do
version=$(yq e '.info.version' "$file")
if [ "$version" != "$expected_version" ]; then
echo "Expected version $expected_version in $file, got $version"
all_match=false
fi
done
$all_match && exit 0 || exit 1
release:
runs-on: ubuntu-latest
needs: [validate-version]
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Create Tag
run: |
VERSION=$(<VERSION)
TAG_NAME="v$VERSION"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git tag -a $TAG_NAME -m "$TAG_NAME"
git push origin $TAG_NAME
- name: Generate CHANGELOG data
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
tag: ${{ env.TAG_NAME }}
includeRefIssues: false
- name: Create Release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
draft: false
makeLatest: true
name: ${{ env.TAG_NAME }}
body: ${{ steps.changelog.outputs.changes }}
tag: ${{ env.TAG_NAME }}
token: ${{ github.token }}