mirror of
https://github.com/Noratrieb/actions-playground.git
synced 2026-01-14 17:05:05 +01:00
Merge pull request #1 from laesse/main
creating only jobs for the services that have changes via matrixes
This commit is contained in:
commit
b8801be95b
4 changed files with 27 additions and 24 deletions
27
.github/workflows/test.yml
vendored
27
.github/workflows/test.yml
vendored
|
|
@ -9,8 +9,7 @@ on:
|
||||||
jobs:
|
jobs:
|
||||||
install-build:
|
install-build:
|
||||||
outputs:
|
outputs:
|
||||||
foo-service: ${{ steps.install.outputs.foo-service }}
|
job-strategy-matrix: ${{ steps.install.outputs.job-strategy-matrix }}
|
||||||
bar-service: ${{ steps.install.outputs.bar-service }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
|
|
@ -23,24 +22,20 @@ jobs:
|
||||||
echo pnpm install
|
echo pnpm install
|
||||||
node ./gen-service-version.js
|
node ./gen-service-version.js
|
||||||
|
|
||||||
foo-service:
|
build-services:
|
||||||
needs: [install-build]
|
needs: [install-build]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{ needs.install-build.outputs.foo-service == 'run' }}
|
if: ${{ needs.install-build.outputs.job-strategy-matrix != '[""]' }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
service: ${{ fromJson(needs.install-build.outputs.job-strategy-matrix) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: gogaille/sparse-checkout@3114de9b3cf84c0829fe84222d8ae8d806fbc794
|
||||||
- name: Build
|
with:
|
||||||
run: |
|
patterns: '${{ matrix.service }} gen-service-version.js'
|
||||||
./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
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
./bar-service/build.sh
|
ls .
|
||||||
|
./${{ matrix.service }}/build.sh
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
echo 'running bar!'
|
echo 'running bar!'
|
||||||
|
echo 'cool new feature -fixing feature'
|
||||||
|
echo 'new feature'
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,5 @@ echo 'Running foo!'
|
||||||
echo 'fixed bug'
|
echo 'fixed bug'
|
||||||
echo 'fixed another bug'
|
echo 'fixed another bug'
|
||||||
echo 'NOT ANOTHER ONE'
|
echo 'NOT ANOTHER ONE'
|
||||||
|
|
||||||
|
echo 'adding a thing here'
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
function latestCommitInDirectory(dirname) {
|
||||||
return String(
|
return String(child_process.execSync(`git log --pretty=format:%H -n 1 ${dirname}`));
|
||||||
child_process.execSync(`git log --pretty=format:%H -n 1 ${dirname}`)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const serviceVersions = {};
|
const serviceVersions = {};
|
||||||
|
|
||||||
const currentCommit = latestCommitInDirectory(".");
|
const currentCommit = latestCommitInDirectory('.');
|
||||||
|
|
||||||
for (const service of services) {
|
for (const service of services) {
|
||||||
serviceVersions[service] = latestCommitInDirectory(service);
|
serviceVersions[service] = latestCommitInDirectory(service);
|
||||||
|
|
@ -19,8 +17,14 @@ for (const service of services) {
|
||||||
console.log(currentCommit);
|
console.log(currentCommit);
|
||||||
console.log(serviceVersions);
|
console.log(serviceVersions);
|
||||||
|
|
||||||
|
let job_strategy_matrix = [];
|
||||||
Object.entries(serviceVersions).forEach(([name, version]) => {
|
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('", "')}"]`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue