Skip to content

Commit

Permalink
test to see if both scenarios work
Browse files Browse the repository at this point in the history
  • Loading branch information
joshjohanning authored Oct 9, 2024
1 parent faf99b7 commit 43cadb1
Showing 1 changed file with 90 additions and 16 deletions.
106 changes: 90 additions & 16 deletions .github/workflows/dynamic-matrix-subvalues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,60 @@ on:
workflow_dispatch:

jobs:
prepare:
prepare-1:
runs-on: ubuntu-latest
outputs:
repositories: ${{ steps.json22222.outputs.repositories }}
repositories: ${{ steps.json.outputs.repositories }}
steps:
- name: Check out repository
uses: actions/checkout@v4

# works
- name: Build matrix
uses: actions/github-script@v7
id: json22222
id: json
with:
script: |
const fs = require('fs');
const path = require('path');
// Define the path to the JSON file
const filePath = path.join(process.env.GITHUB_WORKSPACE, 'index.json');
// Read the JSON file
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading the file:', err);
return;
}
try {
// Parse the JSON data
const jsonData = JSON.parse(data);
// Log the parsed data
console.log('Parsed JSON data:', jsonData);
// Set the output for GitHub Actions
// core.setOutput('repositories', JSON.stringify(jsonData.repositories));
core.setOutput('repositories', JSON.stringify(jsonData));
} catch (parseErr) {
console.error('Error parsing JSON:', parseErr);
}
});
prepare-2:
runs-on: ubuntu-latest
outputs:
repositories: ${{ steps.json.outputs.repositories }}
steps:
- name: Check out repository
uses: actions/checkout@v4

# works
- name: Build matrix
uses: actions/github-script@v7
id: json
with:
script: |
const fs = require('fs');
Expand Down Expand Up @@ -58,22 +100,53 @@ jobs:
# # Append the result to the GitHub Actions output
# echo "repositories=$jq_output" >> $GITHUB_OUTPUT

- name: build matrix 3
id: json
run: |
jq -c '{repositories: .organization.repositories}' index.json
# Process the JSON file and extract repository names
jq_output=$(jq -c '{repositories: .organization.repositories}' index2.json)
# # works
# - name: build matrix 3
# id: json
# run: |
# jq -c '{repositories: .organization.repositories}' index.json
# # Process the JSON file and extract repository names
# jq_output=$(jq -c '{repositories: .organization.repositories}' index2.json)

# # Append the result to the GitHub Actions output
# echo "repositories=$jq_output" >> $GITHUB_OUTPUT

# Append the result to the GitHub Actions output
echo "repositories=$jq_output" >> $GITHUB_OUTPUT
run-matrix-1:
needs: prepare-1
name: ${{ matrix.repositories.name }}
runs-on: ubuntu-latest
strategy:
matrix: "${{ fromJson(needs.prepare-1.outputs.repositories) }}"
fail-fast: false
max-parallel: 15
steps:
- run: echo "${{ toJson(matrix) }}"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
- name: create failures sometimes
run: |
milliseconds=$(date +%s%N | cut -b1-13)
if (( milliseconds % 2 == 0 )); then
# exit 1
exit 0
fi
- name: upload status
if: always()
run: echo "${{ matrix.repository }}, ${{ job.status }}" > ${{ matrix.repository }}.txt
- uses: actions/upload-artifact@v3
if: always()
with:
name: statuses
path: ${{ matrix.repository }}.txt

run-matrix:
needs: prepare
run-matrix-2:
needs: prepare-2
name: ${{ matrix.repositories.name }}
runs-on: ubuntu-latest
strategy:
matrix: "${{ fromJson(needs.prepare.outputs.repositories).organization.myorg }}"
matrix: "${{ fromJson(needs.prepare-2.outputs.repositories).organization.myorg }}"
fail-fast: false
max-parallel: 15
steps:
Expand All @@ -99,10 +172,11 @@ jobs:
path: ${{ matrix.repository }}.txt

test-output:
needs: prepare
needs: [prepare-1, prepare-2]
runs-on: ubuntu-latest
steps:
- run: echo ${{ needs.prepare.outputs.repositories }}
- run: echo ${{ needs.prepare-1.outputs.repositories }}
- run: echo ${{ needs.prepare-2.outputs.repositories }}

# post:
# if: always()
Expand Down

0 comments on commit 43cadb1

Please sign in to comment.