Skip to content

Generate

Generate #8

Workflow file for this run

name: Generate
on:
schedule:
- cron: '0 0 * * 0' # every Sunday at midnight
workflow_dispatch:
jobs:
generate:
env:
VERSION: ''
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- 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
cp /tmp/app_store_connect_api_openapi.json app_store_connect_api_openapi.json
rm -rf /tmp/app_store_connect_api_openapi.zip
rm -rf /tmp/app_store_connect_api_openapi.json
npm run generate
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
if [ "$version" = "$lastVersion" ]; then
echo "No changes detected"
exit 0
fi
npm version $version
# commit the changes as build bot on a new branch named after the new version
echo "VERSION=$version" >> $GITHUB_ENV
git config --global user.email github-actions[bot]@users.noreply.github.com
git config --global user.name "build bot"
git checkout -b "v$version"
git add .
git commit -m "chore: release v$version"
git push origin "v$version"
- uses: actions/github-script@v7
if: env.VERSION != ''
with:
script: |
const version = process.env.VERSION;
const { data: pullRequest } = await github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `chore: release v${version}`,
head: `v${version}`,
base: 'main',
body: 'This PR was automatically generated by the build bot'
})
console.log(`PR created: ${pullRequest.html_url}`)