name: Invoke API on: schedule: - cron: '7 1,5,10,14,17,22 * * *' # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#providing-inputs workflow_dispatch: inputs: unconditional-invoking: description: 'Invoke API unconditionally' type: boolean required: true default: true # https://github.com/actions/checkout/issues/19 jobs: # Random: # runs-on: ubuntu-latest # outputs: # runnable: ${{ steps.decision.outputs.runnable }} # steps: # - name: Checkout code # uses: actions/checkout@v3 # with: # ref: master # token: ${{ secrets.PAT }} # - name: Pull upstream # run: bash wrapper.sh pull sync # - name: Commit and push # run: bash wrapper.sh push "sync with upstream" # - name: Make a decision # id: decision # env: # PASSWD: ${{ secrets.PASSWD }} # run: | # sum=$(cksum <<< "$PASSWD" | cut -f1 -d' ') # m=$(date "+%-m") # d=$(date "+%-d") # h=$(date "+%-H") # [ $(((d + m + sum) % 6)) = 1 ] && exit 0 # [ $(((h + d + sum) & 1)) = 1 ] && exit 0 # echo "::set-output name=runnable::true" Invoke: runs-on: ubuntu-latest if: ${{ github.event.repository.private }} # needs: Random # if: needs.Random.outputs.runnable == 'true' steps: - name: Checkout code uses: actions/checkout@v4 with: ref: master token: ${{ secrets.PAT }} - name: Sync with upstream run: bash wrapper.sh pull - name: Check config files env: USER: ${{ secrets.USER }} run: | bash wrapper.sh has_valid_cfg || { echo "Config files are not valid, please run Register App action." exit 1 } - name: Make a decision id: decision env: PASSWD: ${{ secrets.PASSWD }} run: | [ "${{ inputs.unconditional-invoking }}" = "true" ] && { echo "runnable=true" >> $GITHUB_OUTPUT exit 0 } sum=$(cksum <<< "$PASSWD" | cut -f1 -d' ') m=$(date "+%-m") d=$(date "+%-d") h=$(date "+%-H") [ $(((d + m + sum) % 6)) = 1 ] && exit 0 [ $(((h + d + sum) & 1)) = 1 ] && exit 0 # echo "::set-output name=runnable::true" echo "runnable=true" >> $GITHUB_OUTPUT - name: Set up python if: steps.decision.outputs.runnable == 'true' id: setup-python uses: actions/setup-python@v5 with: python-version: '3.10' - name: Load cached utils if: steps.decision.outputs.runnable == 'true' id: cached-utils uses: actions/cache@v4 with: path: ~/.local key: ${{ runner.os }}-utils-az-poetry-20241016 restore-keys: | ${{ runner.os }}-utils- - name: Install poetry if: steps.decision.outputs.runnable == 'true' && steps.cached-utils.outputs.cache-hit != 'true' uses: snok/install-poetry@v1 with: version: 1.3.2 virtualenvs-create: true virtualenvs-in-project: true installer-parallel: true - name: Load cached venv if: steps.decision.outputs.runnable == 'true' id: cached-poetry-dependencies uses: actions/cache@v4 with: path: .venv key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-venv-${{ hashFiles('**/poetry.lock') }} - name: Install python dependencies if: steps.decision.outputs.runnable == 'true' && steps.cached-poetry-dependencies.outputs.cache-hit != 'true' run: poetry install --no-interaction --no-root --only main - name: Test API if: steps.decision.outputs.runnable == 'true' env: USER: ${{ secrets.USER }} PASSWD: ${{ secrets.PASSWD }} run: bash wrapper.sh invoke - name: Commit and push if: steps.decision.outputs.runnable == 'true' run: bash wrapper.sh push "update app config"