Update dynamic-matrix-subvalues.yml #73
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: dynamic-matrix-test-json | |
on: | |
push: | |
workflow_dispatch: | |
permissions: read-all | |
jobs: | |
env-1: | |
runs-on: ubuntu-latest | |
# environment: prod | |
steps: | |
- run: echo "hi" | |
- run: | | |
var="69$fi" | |
echo "::add-mask::$var" | |
echo $var | |
env-2: | |
runs-on: ubuntu-latest | |
if: always() | |
needs: env-1 | |
steps: | |
- run: echo "${{ needs.env-1.result }}" | |
env-3: | |
runs-on: ubuntu-latest | |
environment: prod2 | |
if: always() | |
needs: env-2 | |
steps: | |
- run: echo "hiiii" | |
prepare-1: | |
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'); | |
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'); | |
const path = require('path'); | |
// Define the path to the JSON file | |
const filePath = path.join(process.env.GITHUB_WORKSPACE, 'index2.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); | |
} | |
}); | |
# works | |
# - name: build matrix 2 | |
# id: json | |
# run: | | |
# jq '{"repositories": [.repositories[].name]}' index.json | |
# jq=$(jq '{"repositories": [.repositories[].name]}' index.json) | |
# # Process the JSON file and extract repository names | |
# jq_output=$(jq -c '{"repositories": [.repositories[].name]}' index.json) | |
# # Append the result to the GitHub Actions output | |
# echo "repositories=$jq_output" >> $GITHUB_OUTPUT | |
# # 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 | |
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 | |
outputs: | |
is-failure: ${{ steps.is-failure.outputs.is-failure }} | |
steps: | |
- run: echo "${{ toJson(matrix) }}" | |
- name: Dump matrix context | |
env: | |
MATRIX_CONTEXT: ${{ toJson(matrix) }} | |
run: echo "$MATRIX_CONTEXT" | |
- if: ${{ matrix.repositories.name == 'repo2' }} | |
run: sleep 2s && exit 1 | |
- name: create failures sometimes | |
run: | | |
milliseconds=$(date +%s%N | cut -b1-13) | |
if (( milliseconds % 2 == 0 )); then | |
exit 1 | |
# exit 0 | |
fi | |
- name: create output var if failure | |
id: is-failure | |
if: failure() | |
run: echo "is-failure=true" >> "$GITHUB_OUTPUT" | |
- name: upload status | |
if: always() | |
run: echo "${{ matrix.repositories.name }}, ${{ job.status }}" > ${{ matrix.repositories.name }}.txt | |
- uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: ${{ matrix.repositories.name }}-1 | |
path: ${{ matrix.repositories.name }}.txt | |
if-failure: | |
needs: [prepare-1, run-matrix-1] | |
runs-on: ubuntu-latest | |
if: always() && needs.run-matrix-1.outputs.is-failure == 'true' | |
steps: | |
- run: echo "${{ needs.run-matrix-1.outputs.is-failure }}" | |
run-matrix-2: | |
needs: prepare-2 | |
name: ${{ matrix.repositories.name }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: "${{ fromJson(needs.prepare-2.outputs.repositories).organization.myorg }}" | |
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.repositories.name }}, ${{ job.status }}" > ${{ matrix.repositories.name }}.txt | |
- uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: ${{ matrix.repositories.name }}-2 | |
path: ${{ matrix.repositories.name }}.txt | |
test-output: | |
needs: [prepare-1, prepare-2] | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo ${{ needs.prepare-1.outputs.repositories }} | |
- run: echo ${{ needs.prepare-2.outputs.repositories }} | |
# post: | |
# if: always() | |
# needs: run-matrix | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/download-artifact@v3 | |
# - name: loop thru | |
# id: get-status | |
# working-directory: statuses | |
# continue-on-error: true | |
# run: | | |
# ISFAILED=0 | |
# failed_repos="" | |
# successful_repos="" | |
# for file in ./*.txt; do | |
# # Read each line in the file | |
# while IFS=, read -r repo status; do | |
# echo "Repo: $repo, Status: $status" | |
# if [ "$status" != "success" ]; then | |
# # Add the repo to the failed list | |
# failed_repos+="$repo\n" | |
# else | |
# # Add the repo to the successful list | |
# successful_repos+="$repo\n" | |
# fi | |
# done < "$file" | |
# done | |
# echo -e "Failed repos: \n$failed_repos" | |
# echo "failed-repos=$failed_repos" >> $GITHUB_OUTPUT | |
# echo -e "Successful repos: \n$successful_repos" | |
# echo "successful-repos=$successful_repos" >> $GITHUB_OUTPUT | |
# if [ $ISFAILED = 1 ]; then | |
# "isfailed=true" >> $GITHUB_OUTPUT | |
# else | |
# "isfailed=false" >> $GITHUB_OUTPUT | |
# fi | |
# - name: print failed repos | |
# run: echo -e "${{ steps.get-status.outputs.failed-repos }}" | |
# - name: or we could use the api to get failed jobs | |
# env: | |
# GH_TOKEN: ${{ github.token }} | |
# run: | | |
# gh api /repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs --jq '.jobs[] | select(.conclusion != "success" and (.name | startswith("run-matrix"))) | { name: .name, conclusion: .conclusion}' | |
# - name: and the api to get success jobs | |
# env: | |
# GH_TOKEN: ${{ github.token }} | |
# run: | | |
# gh api /repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs --jq '.jobs[] | select(.conclusion == "success" and (.name | startswith("run-matrix"))) | { name: .name, conclusion: .conclusion}' | |
# # success, handling canceled / incomplete cases | |
# - uses: actions/github-script@v7 | |
# if: ${{ !steps.get-status.outputs.isfailed && steps.get-status.outputs.failed-repos != ''}} | |
# with: | |
# script: | | |
# let commentBody | |
# commentBody = `Success` | |
# await github.rest.issues.create({ | |
# owner: context.repo.owner, | |
# repo: context.repo.repo, | |
# issue_number: context.issue.number, | |
# title: 'new issue', | |
# body: commentBody.replace(/ +/g, ''), | |
# labels: ['migration', 'gei'] | |
# }) | |
# # failure, handling canceled / incomplete cases | |
# - uses: actions/github-script@v7 | |
# if: ${{ steps.get-status.outputs.isfailed && steps.get-status.outputs.failed-repos != ''}} | |
# with: | |
# script: | | |
# let commentBody | |
# commentBody = `Failure` | |
# await github.rest.issues.create({ | |
# owner: context.repo.owner, | |
# repo: context.repo.repo, | |
# issue_number: context.issue.number, | |
# title: 'new issue', | |
# body: commentBody.replace(/ +/g, ''), | |
# labels: ['migration', 'gei'] | |
# }) | |
# - name: Dump GitHub context | |
# env: | |
# GITHUB_CONTEXT: ${{ toJSON(github) }} | |
# run: echo "$GITHUB_CONTEXT" | |
# - name: Dump job context | |
# run: echo '${{ toJSON(job) }}' | |
# - name: Dump steps context | |
# run: echo '${{ toJSON(steps) }}' | |
# - name: Dump runner context | |
# run: echo '${{ toJSON(runner) }}' | |
# - name: Dump strategy context | |
# run: echo '${{ toJSON(strategy) }}' | |
# - name: Dump matrix context | |
# run: echo '${{ toJSON(matrix) }}' | |
# - run: echo ${{ matrix.repository }} | |
deploy-1: | |
runs-on: ubuntu-latest | |
environment: test | |
steps: | |
- run: echo "hi" | |
deploy-2: | |
runs-on: ubuntu-latest | |
environment: test | |
needs: deploy-1 | |
steps: | |
- run: echo "hi" | |