|
| 1 | +# Copyright 2023 D2iQ, Inc. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +name: devbox-update |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + schedule: |
| 9 | + - cron: "0 0 * * *" |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + devbox-update: |
| 17 | + if: github.ref_type == 'branch' |
| 18 | + runs-on: ubuntu-22.04 |
| 19 | + defaults: |
| 20 | + run: |
| 21 | + shell: bash |
| 22 | + steps: |
| 23 | + - name: Check out code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Install devbox |
| 27 | + uses: jetpack-io/[email protected] |
| 28 | + with: |
| 29 | + enable-cache: true |
| 30 | + |
| 31 | + - name: Run devbox update |
| 32 | + run: devbox update |
| 33 | + |
| 34 | + - name: Get number of versions changed |
| 35 | + id: devbox-versions-changed |
| 36 | + run: | |
| 37 | + echo "number_changed=$(git diff --unified=0 devbox.lock | grep -c \"version\":)" >>"${GITHUB_OUTPUT}" |
| 38 | +
|
| 39 | + - name: Commit changes and create PR |
| 40 | + if: steps.devbox-versions-changed.outputs.number_changed > 0 |
| 41 | + env: |
| 42 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + FILE_TO_COMMIT: devbox.lock |
| 44 | + DESTINATION_BRANCH: scheduled-devbox-update-${{ github.ref_name }} |
| 45 | + run: | |
| 46 | + git branch "${DESTINATION_BRANCH}" |
| 47 | + git push origin "${DESTINATION_BRANCH}" |
| 48 | +
|
| 49 | + TODAY="$( date -u '+%Y-%m-%d' )" |
| 50 | + MESSAGE="build(${{ github.ref_name }}): Latest devbox update (${TODAY})" |
| 51 | + SHA=$( git rev-parse "${DESTINATION_BRANCH}":"${FILE_TO_COMMIT}" ) |
| 52 | + gh api --method PUT "/repos/:owner/:repo/contents/${FILE_TO_COMMIT}" \ |
| 53 | + --field message="${MESSAGE}" \ |
| 54 | + --field content=@<( base64 -i "${FILE_TO_COMMIT}" ) \ |
| 55 | + --field encoding="base64" \ |
| 56 | + --field branch="${DESTINATION_BRANCH}" \ |
| 57 | + --field sha="${SHA}" |
| 58 | +
|
| 59 | + gh pr create --base "${{ github.ref_name }}" --head "${DESTINATION_BRANCH}" --fill |
0 commit comments