Automatic Package Update Check #85
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is maintained by velocitas CLI, do not modify manually. Change settings in .velocitas.json | |
# Copyright (c) 2024 Contributors to the Eclipse Foundation | |
# | |
# This program and the accompanying materials are made available under the | |
# terms of the Apache License, Version 2.0 which is available at | |
# https://www.apache.org/licenses/LICENSE-2.0. | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
# License for the specific language governing permissions and limitations | |
# under the License. | |
# | |
# SPDX-License-Identifier: Apache-2.0 | |
name: Automatic Package Update Check | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 4 * * *" | |
jobs: | |
package_update_check: | |
if: github.repository_owner == 'eclipse-velocitas' | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.VELOCITAS_PROJECT_TOKEN }} | |
- name: Use devcontainer for upgrade and PR creation | |
uses: devcontainers/ci@v0.3 | |
with: | |
runCmd: | | |
sudo apt-get update && sudo apt-get install -y gh | |
echo "${{ secrets.VELOCITAS_PROJECT_TOKEN }}" | gh auth login --with-token | |
velocitas upgrade --ignore-bounds && velocitas init && velocitas sync | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
if [ -n "$(git status --porcelain)" ]; then | |
PR_TITLE="Automated Package Update" | |
PR_BODY="This pull request was created automatically by GitHub Actions to update package versions." | |
# Check if a PR with the same title already exists | |
PR_EXISTING=$(gh pr list --state open --search "$PR_TITLE" --json number | jq -r '.[0].number // empty') | |
if [ -n "$PR_EXISTING" ]; then | |
echo "Existing PR found (#${PR_EXISTING}). Editing..." | |
git checkout . | |
gh pr checkout "$PR_EXISTING" | |
velocitas upgrade --ignore-bounds && velocitas init && velocitas sync | |
git add . | |
git commit -m "Update velocitas package versions" | |
if [ $? -eq 0 ]; then | |
git push | |
gh pr comment "$PR_EXISTING" --body "Updated PR with latest package updates" | |
fi | |
else | |
git add . | |
git commit -m "Update velocitas package versions" | |
BRANCH_NAME="automated-update-${{ github.sha }}" | |
git push origin HEAD:$BRANCH_NAME | |
echo "Creating new PR..." | |
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head $BRANCH_NAME --base main | |
fi | |
else | |
echo "No changes detected. Skip creating Pull Request." | |
fi |