From 20c01510ee26d7d0b3af21aec710cf5b63938f06 Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:15:56 +0200 Subject: [PATCH 01/12] use matrix --- .github/workflows/test.yml | 22 ++++++---------------- gen-service-version.js | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2b8d8a6..751fec7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,8 +9,7 @@ on: jobs: install-build: outputs: - foo-service: ${{ steps.install.outputs.foo-service }} - bar-service: ${{ steps.install.outputs.bar-service }} + job-strategy-matrix: ${{ steps.install.outputs.job-strategy-matrix }} runs-on: ubuntu-latest steps: - name: Checkout code @@ -23,24 +22,15 @@ jobs: echo pnpm install node ./gen-service-version.js - foo-service: + build-services: needs: [install-build] runs-on: ubuntu-latest - if: ${{ needs.install-build.outputs.foo-service == 'run' }} + strategy: + matrix: + service: { { needs.install-build.outputs.job-strategy-matrix } } steps: - name: Checkout code uses: actions/checkout@v3 - name: Build run: | - ./foo-service/build.sh - - bar-service: - needs: [install-build] - runs-on: ubuntu-latest - if: ${{ needs.install-build.outputs.bar-service == 'run' }} - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Build - run: | - ./bar-service/build.sh + ./{{ matrix.service }}/build.sh diff --git a/gen-service-version.js b/gen-service-version.js index f4732cc..5bbd457 100644 --- a/gen-service-version.js +++ b/gen-service-version.js @@ -1,16 +1,14 @@ -const child_process = require("child_process"); +const child_process = require('child_process'); -const services = ["bar-service", "foo-service"]; +const services = ['bar-service', 'foo-service']; function latestCommitInDirectory(dirname) { - return String( - child_process.execSync(`git log --pretty=format:%H -n 1 ${dirname}`) - ); + return String(child_process.execSync(`git log --pretty=format:%H -n 1 ${dirname}`)); } const serviceVersions = {}; -const currentCommit = latestCommitInDirectory("."); +const currentCommit = latestCommitInDirectory('.'); for (const service of services) { serviceVersions[service] = latestCommitInDirectory(service); @@ -19,8 +17,14 @@ for (const service of services) { console.log(currentCommit); console.log(serviceVersions); +let job_strategy_matrix = []; Object.entries(serviceVersions).forEach(([name, version]) => { - const skip = version === currentCommit ? "run" : "skip"; + const skip = version === currentCommit ? 'run' : 'skip'; - console.log(`::set-output name=${name}::${skip}`); + console.log(`${name}::${skip}`); + if (version === currentCommit) { + job_strategy_matrix.push(name); + } }); + +console.log(`::set-output name=job-strategy-matrix::[${job_strategy_matrix.join(', ')}]`); From e81e838e6924379833b69edd921cbbdc534da900 Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:17:15 +0200 Subject: [PATCH 02/12] bar update --- bar-service/bar.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bar-service/bar.sh b/bar-service/bar.sh index 019eb5d..3d80354 100755 --- a/bar-service/bar.sh +++ b/bar-service/bar.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash echo 'running bar!' +echo 'cool new feature' \ No newline at end of file From 06d633503e8f5e754a98ac6bfab6291967cde53e Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:19:38 +0200 Subject: [PATCH 03/12] fix workflow --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 751fec7..3425eec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,10 +27,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - service: { { needs.install-build.outputs.job-strategy-matrix } } + service: ${{ needs.install-build.outputs.job-strategy-matrix }} steps: - name: Checkout code uses: actions/checkout@v3 - name: Build run: | - ./{{ matrix.service }}/build.sh + ./${{ matrix.service }}/build.sh From e2fb95586b121c615917f4659e39a4d7110c64be Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:21:52 +0200 Subject: [PATCH 04/12] fix for no changes --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3425eec..2bfbeca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,6 +25,7 @@ jobs: build-services: needs: [install-build] runs-on: ubuntu-latest + if: ${{ needs.install-build.outputs.job-strategy-matrix != "[]"}} strategy: matrix: service: ${{ needs.install-build.outputs.job-strategy-matrix }} From 90c069cf6510dab8f6b6fe2d5839b02d16d82454 Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:23:11 +0200 Subject: [PATCH 05/12] fix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2bfbeca..b874853 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: build-services: needs: [install-build] runs-on: ubuntu-latest - if: ${{ needs.install-build.outputs.job-strategy-matrix != "[]"}} + if: ${{ needs.install-build.outputs.job-strategy-matrix != '[]' }} strategy: matrix: service: ${{ needs.install-build.outputs.job-strategy-matrix }} From b5cc58b901f16127e7d751f7961a271063eecdd4 Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:24:00 +0200 Subject: [PATCH 06/12] new thing bar --- bar-service/bar.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bar-service/bar.sh b/bar-service/bar.sh index 3d80354..9b8d697 100755 --- a/bar-service/bar.sh +++ b/bar-service/bar.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash echo 'running bar!' -echo 'cool new feature' \ No newline at end of file +echo 'cool new feature -fixing feature' \ No newline at end of file From 04cddf10433b5b4fcd11738768c4b4bda8f52531 Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:27:39 +0200 Subject: [PATCH 07/12] use json method --- .github/workflows/test.yml | 4 ++-- gen-service-version.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b874853..cd041f8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,10 +25,10 @@ jobs: build-services: needs: [install-build] runs-on: ubuntu-latest - if: ${{ needs.install-build.outputs.job-strategy-matrix != '[]' }} + if: ${{ needs.install-build.outputs.job-strategy-matrix != '[""]' }} strategy: matrix: - service: ${{ needs.install-build.outputs.job-strategy-matrix }} + service: ${{ fromJson(needs.install-build.outputs.job-strategy-matrix) }} steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/gen-service-version.js b/gen-service-version.js index 5bbd457..ef781ba 100644 --- a/gen-service-version.js +++ b/gen-service-version.js @@ -27,4 +27,4 @@ Object.entries(serviceVersions).forEach(([name, version]) => { } }); -console.log(`::set-output name=job-strategy-matrix::[${job_strategy_matrix.join(', ')}]`); +console.log(`::set-output name=job-strategy-matrix::["${job_strategy_matrix.join('", "')}"]`); From 521d29b3e88ddae6124ea4cab29a9164e8d69bee Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:28:57 +0200 Subject: [PATCH 08/12] new bar feature --- bar-service/bar.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bar-service/bar.sh b/bar-service/bar.sh index 9b8d697..e8245a6 100755 --- a/bar-service/bar.sh +++ b/bar-service/bar.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash echo 'running bar!' -echo 'cool new feature -fixing feature' \ No newline at end of file +echo 'cool new feature -fixing feature' +echo 'new feature' \ No newline at end of file From 7167309bf5163832ad82eb78c2d963c94aa2c82c Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 22:30:04 +0200 Subject: [PATCH 09/12] update both --- bar-service/bar.sh | 4 +++- foo-service/foo.sh | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bar-service/bar.sh b/bar-service/bar.sh index e8245a6..8d3b769 100755 --- a/bar-service/bar.sh +++ b/bar-service/bar.sh @@ -2,4 +2,6 @@ echo 'running bar!' echo 'cool new feature -fixing feature' -echo 'new feature' \ No newline at end of file +echo 'new feature' + +echo 'and here' \ No newline at end of file diff --git a/foo-service/foo.sh b/foo-service/foo.sh index 14338a5..8163df7 100755 --- a/foo-service/foo.sh +++ b/foo-service/foo.sh @@ -4,3 +4,5 @@ echo 'Running foo!' echo 'fixed bug' echo 'fixed another bug' echo 'NOT ANOTHER ONE' + +echo 'adding a thing here' From 7cd19c34d5f4e85a03b2bc700fef8af61b757dc7 Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 23:48:30 +0200 Subject: [PATCH 10/12] sparse checkout --- .github/workflows/test.yml | 4 +++- foo-service/foo.sh | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd041f8..da59123 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,9 @@ jobs: service: ${{ fromJson(needs.install-build.outputs.job-strategy-matrix) }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: gogaille/sparse-checkout + patterns: '${{ matrix.service }} gen-service-version.js' - name: Build run: | + ls . ./${{ matrix.service }}/build.sh diff --git a/foo-service/foo.sh b/foo-service/foo.sh index 8163df7..d13fe5e 100755 --- a/foo-service/foo.sh +++ b/foo-service/foo.sh @@ -6,3 +6,5 @@ echo 'fixed another bug' echo 'NOT ANOTHER ONE' echo 'adding a thing here' + +# important change From 83282a2f676ffc70111a53e7c0fb2254d037f7ba Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 23:50:06 +0200 Subject: [PATCH 11/12] fix --- .github/workflows/test.yml | 2 ++ bar-service/bar.sh | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index da59123..9e16fa0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,9 @@ jobs: steps: - name: Checkout code uses: gogaille/sparse-checkout + with: patterns: '${{ matrix.service }} gen-service-version.js' + - name: Build run: | ls . diff --git a/bar-service/bar.sh b/bar-service/bar.sh index 8d3b769..89a1700 100755 --- a/bar-service/bar.sh +++ b/bar-service/bar.sh @@ -3,5 +3,3 @@ echo 'running bar!' echo 'cool new feature -fixing feature' echo 'new feature' - -echo 'and here' \ No newline at end of file From 4e216ca6cec4a958f1dbf139d2a49d8ec04dbaf5 Mon Sep 17 00:00:00 2001 From: Laesse Date: Mon, 15 Aug 2022 23:51:15 +0200 Subject: [PATCH 12/12] fix 2 --- .github/workflows/test.yml | 2 +- foo-service/foo.sh | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9e16fa0..a63d5aa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: service: ${{ fromJson(needs.install-build.outputs.job-strategy-matrix) }} steps: - name: Checkout code - uses: gogaille/sparse-checkout + uses: gogaille/sparse-checkout@3114de9b3cf84c0829fe84222d8ae8d806fbc794 with: patterns: '${{ matrix.service }} gen-service-version.js' diff --git a/foo-service/foo.sh b/foo-service/foo.sh index d13fe5e..8163df7 100755 --- a/foo-service/foo.sh +++ b/foo-service/foo.sh @@ -6,5 +6,3 @@ echo 'fixed another bug' echo 'NOT ANOTHER ONE' echo 'adding a thing here' - -# important change