Bump DCF Version #8320
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
name: Bump DCF Version | |
on: | |
schedule: | |
- cron: "0 */1 * * *" | |
workflow_dispatch: | |
jobs: | |
check-DCF-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get latest commit timestamp | |
id: get-commit | |
run: | | |
# Fetch the latest commit timestamp from the other repository | |
LATEST_TIMESTAMP=$(curl -s https://api.github.com/repos/digitalcampusframework/dcf/commits/3.0 | jq -r '.commit.committer.date') | |
echo "timestamp=$LATEST_TIMESTAMP" >> $GITHUB_OUTPUT | |
- name: Compare commit timestamps | |
id: compare-commits | |
run: | | |
# Get the current timestamp | |
CURRENT_TIMESTAMP=$(date +%s) | |
echo "Current timestamp: $CURRENT_TIMESTAMP" | |
# Get the timestamp of the latest commit | |
LATEST_TIMESTAMP=$(date -d "${{ steps.get-commit.outputs.timestamp }}" +%s) | |
echo "Latest commit timestamp: $LATEST_TIMESTAMP" | |
# Calculate the time difference in seconds | |
TIME_DIFF=$((CURRENT_TIMESTAMP - LATEST_TIMESTAMP)) | |
echo "Time difference: $TIME_DIFF seconds" | |
# Check if there was a commit within the last 1 hours (3600 seconds) | |
if [ $TIME_DIFF -lt 3600 ]; then | |
echo "Recent commit found!" | |
echo "recent_commit=true" >> $GITHUB_OUTPUT | |
else | |
echo "No recent commit" | |
echo "recent_commit=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Modify package-lock.json | |
id: modify-file | |
if: ${{ steps.compare-commits.outputs.recent_commit == 'true' }} | |
run: | | |
# Read the package-lock.json file | |
FILE_PATH="package-lock.json" | |
FILE_CONTENT=$(cat $FILE_PATH) | |
# Find and replace the commit hash | |
NEW_COMMIT_HASH=$(curl -s https://api.github.com/repos/digitalcampusframework/dcf/commits/3.0 | jq -r '.sha') | |
UPDATED_CONTENT=$(echo "$FILE_CONTENT" | jq --arg new_version "git+ssh://[email protected]/digitalcampusframework/dcf.git#$NEW_COMMIT_HASH" '.packages."node_modules/dcf".resolved = $new_version') | |
# Overwrite the modified content to the file | |
echo "$UPDATED_CONTENT" > $FILE_PATH | |
- name: Create pull request | |
uses: gr2m/create-or-update-pull-request-action@v1 | |
if: ${{ steps.compare-commits.outputs.recent_commit == 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
title: "Bump DCF" | |
body: "Updated DCF commit hash" | |
branch: "gw-dcf-bump-branch" | |
commit-message: "Bumped DCF" | |
labels: dependency | |
reviewers: tommyneu, skoolbus39 | |
auto-merge: squash | |
update-pull-request-title-and-body: false |