Skip to content

Instantly share code, notes, and snippets.

@pf1ll
Last active January 16, 2023 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pf1ll/0b186ab8dca4edbfa647868f5b41021a to your computer and use it in GitHub Desktop.
Save pf1ll/0b186ab8dca4edbfa647868f5b41021a to your computer and use it in GitHub Desktop.
Пример рабочего процесса для сохранения данных в БД с помощью cUrl
name: Initialize app version
on:
workflow_call:
secrets:
databaseUri:
required: true
outputs:
VERSION_NAME:
value: ${{ jobs.InitAppVersion.outputs.versionName }}
VERSION_CODE:
value: ${{ jobs.InitAppVersion.outputs.versionCode }}
jobs:
InitAppVersion:
name: Init app version
runs-on: ubuntu-latest
outputs:
versionName: ${{ steps.finish.outputs.versionName }}
versionCode: ${{ steps.finish.outputs.versionCode }}
steps:
# Получаем из базы последние значения versionName и versionCode если хоть одно поле пустое
- name: Pull build info from realtime database
id: pull
if: ${{ github.event.inputs.versionName == '' || github.event.inputs.versionCode == '' }}
run: |
curl --show-error --fail --request GET --url "${{ secrets.databaseUri }}" > response.json
echo '::set-output name=lastVersionName::'$(jq -r '.version_name' response.json)
echo '::set-output name=lastVersionCode::'$(jq -r '.version_code' response.json)
# Устанавливаем значение номера версии
- name: Initial version name
run: echo "newVersionName=${{ github.event.inputs.versionName || steps.pull.outputs.lastVersionName }}" >> $GITHUB_ENV
# Устанавливаем значение номера билда
- name: Initial version code
env:
versionCode: $((${{ steps.pull.outputs.lastVersionCode }}+1))
run: echo "newVersionCode=${{ github.event.inputs.versionCode || env.versionCode }}" >> $GITHUB_ENV
# Сохраняем значение номера билда в базу если значение брали из нее
- name: Push version code to realtime database
if: ${{ github.event.inputs.versionCode == '' }}
run: curl --show-error --fail --request PATCH --url "${{ secrets.databaseUri }}" --data-raw "{\"version_code\":${{ env.newVersionCode }}}"
# Печатаем информацию по версии
- name: Workflow summary
run: |
echo "### Build info:" >> $GITHUB_STEP_SUMMARY
echo "| Last version name | Last version code | Input version name | Input version code | Result build version |" >> $GITHUB_STEP_SUMMARY
echo "| :-----: | :-----: | :------: | :------: | :------: |" >> $GITHUB_STEP_SUMMARY
echo "| ${{ steps.pull.outputs.lastVersionName }} | ${{ steps.pull.outputs.lastVersionCode }} | ${{ github.event.inputs.versionName }} | ${{ github.event.inputs.versionCode }} | ${{ env.newVersionName }} (${{ env.newVersionCode }}) |" >> $GITHUB_STEP_SUMMARY
# Указываем выходные данные
- name: Setup outputs
id: finish
run: |
echo "::set-output name=versionName::${{ env.newVersionName }}"
echo "::set-output name=versionCode::${{ env.newVersionCode }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment