backend-update #126
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: Backend Update Workflow | |
on: | |
workflow_dispatch: | |
repository_dispatch: | |
types: [backend-update] | |
jobs: | |
update-client: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Determine Branch and SHA for Update | |
id: set_branch_and_sha | |
run: | | |
echo "branch=$(echo ${{ github.event.client_payload.ref }} | awk -F'/' '{print $NF}' || 'develop')" >> $GITHUB_ENV | |
echo "BACKEND_SHA=$(echo ${{ github.event.client_payload.sha }} || 'MANUAL_RUN')" >> $GITHUB_ENV | |
- name: Checkout Client Repository | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ env.branch }} | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install Dependencies | |
run: npm install | |
- name: Run Update Script | |
run: | | |
if [[ ${{ env.branch }} == 'main' ]]; then | |
npm run update-swagger:main | |
if ! cmp --silent ./swagger-main.json ./swagger.json; then | |
mv ./swagger-main.json ./swagger.json | |
echo "Files differ, running npm run gen" | |
echo "NEEDS_GEN=true" >> $GITHUB_ENV | |
else | |
echo "Files are identical, no need to run npm run gen" | |
echo "NEEDS_GEN=false" >> $GITHUB_ENV | |
fi | |
elif [[ ${{ env.branch }} == 'develop' ]]; then | |
npm run update-swagger:dev | |
if ! cmp --silent ./swagger-develop.json ./swagger.json; then | |
mv ./swagger-develop.json ./swagger.json | |
echo "Files differ, running npm run gen" | |
echo "NEEDS_GEN=true" >> $GITHUB_ENV | |
else | |
echo "Files are identical, no need to run npm run gen" | |
echo "NEEDS_GEN=false" >> $GITHUB_ENV | |
fi | |
fi | |
- name: Generate Client Code | |
if: env.NEEDS_GEN == 'true' | |
run: npm run genbuild | |
- name: Configure Git | |
if: env.NEEDS_GEN == 'true' | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
- name: Push Changes to New Branch | |
if: env.NEEDS_GEN == 'true' | |
run: | | |
git checkout -b Update/${{ env.branch }}-${{ env.BACKEND_SHA }} | |
git add . | |
git commit -m "Update from backend ${{env.BACKEND_SHA}}" --author="GitHub Actions Bot <[email protected]>" | |
git push origin Update/${{ env.branch }}-${{ env.BACKEND_SHA }} | |
- name: Create Pull Request | |
uses: repo-sync/pull-request@v2 | |
if: env.NEEDS_GEN == 'true' | |
with: | |
pr_title: "Update from Backend" | |
pr_body: "Automated PR to update client after backend changes." | |
source_branch: "Update/${{ env.branch }}-${{ env.BACKEND_SHA }}" | |
destination_branch: ${{ env.branch }} |