Skip to content

Generate

Generate #37

Workflow file for this run

name: Generate
on:
schedule:
- cron: '0 0 * * 0' # every Sunday at midnight
workflow_dispatch:
jobs:
generate:
permissions:
contents: write
pull-requests: write
env:
VERSION: ''
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: |
npm install
npm audit fix --save --force
# download the latest version of the apple app store connect api schema
# https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip
curl -L https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip -o app-store-connect-openapi-specification.zip
unzip app-store-connect-openapi-specification.zip -d /tmp
# find fist *.json file in the directory
schemaPath=$(find /tmp -type f -name "*.json" | head -n 1)
cp $schemaPath app_store_connect_api_openapi.json
rm -rf app-store-connect-openapi-specification.zip
rm -rf $schemaPath
if [ $? -ne 0 ]; then
echo "Error: npm run generate failed"
exit 1
fi
# get the last version of the package from the npm registry
lastVersion=$(npm show @rage-against-the-pixel/app-store-connect-api version)
# set the package version to be the same as the schema version
version=$(node -p "require('./app_store_connect_api_openapi.json').info.version")
# if the schema version is the same as the last version of the package, exit
echo "$lastVersion -> $version"
# if the version is less than or equal to the last version, exit
if npx semver "$version" -r "<=$lastVersion"; then
echo "No changes detected"
exit 0
else
echo "New version detected"
fi
git config --global user.email github-actions[bot]@users.noreply.github.com
git config --global user.name "build bot"
git status
git stash
# set the package version to be the same as the schema version
npm version $version
git stash pop
npm run generate
# commit the changes as build bot on a new branch named after the new version
echo "VERSION=$version" >> $GITHUB_ENV
git checkout -b "release/v$version"
git add .
git commit -m "chore: release v$version"
git push origin "release/v$version"
- uses: actions/github-script@v7
if: env.VERSION != ''
with:
script: |
const version = process.env.VERSION;
const changeNotesVersion = version.split('.').slice(0, 2).join('-');
const appStoreConnectChangeNotesUri = `https://developer.apple.com/documentation/appstoreconnectapi/app-store-connect-api-${changeNotesVersion}-release-notes`;
const { data: pullRequest } = await github.rest.pulls.create({
title: `chore: release v${version}`,
owner: context.repo.owner,
repo: context.repo.repo,
base: 'main',
head: `release/v${version}`,
body: `This PR was automatically generated by the build bot\n[App Store Connect API ${version} Change Notes](${appStoreConnectChangeNotesUri})`,
})
console.log(`PR created: ${pullRequest.html_url}`)