Skip to content

Commit

Permalink
adjust management of dates 2
Browse files Browse the repository at this point in the history
  • Loading branch information
wkelly17 committed Nov 19, 2024
1 parent d8b1140 commit 79eea5c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
27 changes: 15 additions & 12 deletions .github/workflows/addDatesMeta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,36 @@ jobs:
with:
fetch-depth: 0 # needed for full meta history

- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq

- name: Set git config
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '[email protected]'
git config --global core.quotePath false
- name: get inputs for job
# note the herdocs for multiline outputs
run: |
# Collect all files
all_files=$(git ls-tree -r --name-only HEAD)
echo "all_files<<EOF" >> $GITHUB_ENV
echo "$all_files" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Collect modified files
files_modified=$(git diff --name-only HEAD~1 HEAD)
echo "files_modified<<EOF" >> $GITHUB_ENV
echo "$files_modified" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Read metadata.json
existing_meta=$(cat metadata.json)
echo "all_files=$all_files" >> $GITHUB_ENV
echo "files_modified=$files_modified" >> $GITHUB_ENV
echo "existing_meta=$existing_meta" >> $GITHUB_ENV
echo "existing_meta<<EOF" >> $GITHUB_ENV
echo "$existing_meta" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Run dates.js
uses: ./actions/dates
with:
token: ${{ secrets.GITHUB_TOKEN }}
all-files: ${{ env.all_files }}
files-modified: ${{ env.files_modified }}
existing-meta: ${{ env.existing_meta }}

- name: Commit if different
run: |
git add metadata.json
git commit -m "Automated Update of metadata.json with latest file dates" || echo "No changes to commit"
git push || echo "No changes to push"
3 changes: 3 additions & 0 deletions actions/dates/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ async function run() {
const metaParsed = JSON.parse(exisitingMetadataJson); //Record<string string>
const filesModifiedArr = filesModifiedInCommit.split("\n");
const allFilesInGitArr = filesModifiedInCommit.split("\n");
octokit.log.info(
`Received ${allFilesInGit.length} all files and ${filesModifiedInCommit.length} modified files`
);

const metadataUpdated = Object.entries(allFilesInGitArr).reduce(
(acc, [key, value]) => {
Expand Down

0 comments on commit 79eea5c

Please sign in to comment.