Skip to content

Generate Action

Generate Action #42

Workflow file for this run

name: Generate Action
on:
workflow_call:
inputs:
version:
description: 'Liquibase version'
required: true
default: '4.29.0'
type: string
workflow_dispatch:
inputs:
version:
description: 'Liquibase version'
required: true
default: '4.29.0'
type: string
permissions:
contents: write
pull-requests: write
jobs:
create-command-list:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check if feature branch for ${{ inputs.version }} exists
id: branch_check
run: |
BRANCH_EXISTS=$(git ls-remote --exit-code --heads origin ${{ inputs.version }} &>/dev/null && echo "true" || echo "false")
echo "BRANCH_EXISTS=$BRANCH_EXISTS" >> $GITHUB_ENV
- name: Create or checkout branch
run: |
if [ "${{ env.BRANCH_EXISTS }}" = "false" ]; then
git checkout -b ${{ inputs.version }}
git push origin ${{ inputs.version }}
else
git fetch origin ${{ inputs.version }}
git checkout ${{ inputs.version }}
git reset --hard origin/${{ inputs.version }}
fi
- name: Install protoc and npm
run: |
sudo apt-get install -y protobuf-compiler npm
npm install proto ts-proto
- name: Build liquibase-protobuf-generator
run: docker build -t liquibase-protobuf-generator:${{ inputs.version }} . --build-arg VERSION=${{ inputs.version }}
- name: Generate liquibase command list
run: docker run --rm -v $(pwd):/proto liquibase-protobuf-generator:${{ inputs.version }} --output-file=commands.json list-commands
- name: Iterate over commands and execute Docker command
run: |
COMMANDS=$(cat commands.json | jq -r '.[]')
IFS=$'\n'
for command in $COMMANDS; do
docker run --rm -v $(pwd):/proto liquibase-protobuf-generator:${{ inputs.version }} generate-protobuf --target-command="$command" --output-dir /proto
COMMAND="${command//-/_}"
COMMAND="${COMMAND/ /_}"
protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=. --ts_proto_opt=exportCommonSymbols=false --experimental_allow_proto3_optional $COMMAND.proto
done
mkdir -p proto-commands
mv *.ts ./proto-commands
- name: Update liquibase binaries
run: |
wget -q https://github.com/liquibase/liquibase/releases/download/v${{ inputs.version }}/liquibase-${{ inputs.version }}.zip
unzip liquibase-${{ inputs.version }}.zip -d liquibase
rm -rf ./bin/liquibase
mv liquibase ./bin
rm -rf liquibase-${{ inputs.version }}.zip
- name: Configure git user
run: |
git config --global init.defaultBranch master
git config --global user.name "liquibot"
git config --global user.email "[email protected]"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit-message: Auto Pull Request for protobuf files [liquibase ${{ inputs.version }}]
title: Auto Pull Request for protobuf files [liquibase ${{ inputs.version }}]
body: Auto Pull Request for protobuf files [liquibase ${{ inputs.version }}]
branch: ${{ inputs.version }}
base: master