Fetch new commits from remote repos #3
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: Fetch new commits from remote repos | |
on: | |
workflow_dispatch: | |
inputs: | |
number_input: | |
description: "Enter a number of days from today (default is 30 days)." | |
required: true | |
default: "30" | |
jobs: | |
run-swift-script: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/[email protected] | |
- name: Load secrets from 1Password | |
id: onepw_secrets | |
uses: 1password/[email protected] | |
with: | |
export-env: true # Export loaded secrets as environment variables | |
env: | |
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | |
GITHUB_TOKEN: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/GitHub generic action token for all repos/credential" | |
- name: Run Swift Script | |
id: run-swift-script | |
run: | | |
NUMBER_OF_DAYS=${{ github.event.inputs.number_input }} | |
OUTPUT=$(swift scripts/monitor-remote-repos-for-new-commits.swift $NUMBER_OF_DAYS) | |
echo "swift_output=$OUTPUT" >> $GITHUB_ENV | |
env: | |
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }} | |
- name: Parse Output | |
id: parse-output | |
run: | | |
FOUND_COMMITS=$(echo "$swift_output" | jq -r '.found_commits') | |
BRANCH_NAME=$(echo "$swift_output" | jq -r '.branch_name') | |
ISSUE_TITLE=$(echo "$swift_output" | jq -r '.issue_title') | |
# First get the escaped version for workflow variables | |
ISSUE_BODY=$(echo "$swift_output" | jq -r '.issue_body' | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/|/\\|/g') | |
# Output the regular variables | |
echo "found_commits=$FOUND_COMMITS" >> $GITHUB_OUTPUT | |
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
echo "issue_title=$ISSUE_TITLE" >> $GITHUB_OUTPUT | |
# Output the unescaped body using EOF delimiter for proper multiline handling | |
echo "issue_body<<EOF" >> $GITHUB_OUTPUT | |
echo "$swift_output" | jq -r '.issue_body' >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Create issue | |
id: create-issue | |
if: steps.parse-output.outputs.found_commits == 'true' | |
uses: dacbd/[email protected] | |
with: | |
token: ${{ env.GITHUB_TOKEN }} | |
assignees: Sergiodero | |
title: ${{ steps.parse-output.outputs.issue_title }} | |
body: ${{ steps.parse-output.outputs.issue_body }} |