Skip to content

build: Add devbox update scheduled job #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/devbox-update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2024 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: devbox-update

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"

permissions:
contents: write
pull-requests: write

jobs:
devbox-update:
if: github.ref_type == 'branch'
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Install devbox
uses: jetpack-io/[email protected]
with:
enable-cache: true

- name: Run devbox update
run: devbox update

- name: Get number of versions changed
id: devbox-versions-changed
run: |
echo "number_changed=$(git diff --unified=0 devbox.lock | grep -c \"version\":)" >>"${GITHUB_OUTPUT}"

- name: Commit changes and create PR
if: steps.devbox-versions-changed.outputs.number_changed > 0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILE_TO_COMMIT: devbox.lock
DESTINATION_BRANCH: scheduled-devbox-update-${{ github.ref_name }}
run: |
git branch "${DESTINATION_BRANCH}"
git push origin "${DESTINATION_BRANCH}"

TODAY="$( date -u '+%Y-%m-%d' )"
MESSAGE="build(${{ github.ref_name }}): Latest devbox update (${TODAY})"
SHA=$( git rev-parse "${DESTINATION_BRANCH}":"${FILE_TO_COMMIT}" )
gh api --method PUT "/repos/:owner/:repo/contents/${FILE_TO_COMMIT}" \
--field message="${MESSAGE}" \
--field content=@<( base64 -i "${FILE_TO_COMMIT}" ) \
--field encoding="base64" \
--field branch="${DESTINATION_BRANCH}" \
--field sha="${SHA}"

gh pr create --base "${{ github.ref_name }}" --head "${DESTINATION_BRANCH}" --fill