Skip to content

Commit e34d8e0

Browse files
committed
Use current branch when triggering other workflows
1 parent 8ffd558 commit e34d8e0

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

.github/workflows/all.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,41 @@ jobs:
1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
21+
22+
- name: Download branch name artifact
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
run_id: context.payload.workflow_run.id,
30+
});
31+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
32+
return artifact.name == "branch_name"
33+
})[0];
34+
let download = await github.rest.actions.downloadArtifact({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
artifact_id: matchArtifact.id,
38+
archive_format: 'zip',
39+
});
40+
const fs = require('fs');
41+
const path = require('path');
42+
const temp = '${{ runner.temp }}/artifacts';
43+
if (!fs.existsSync(temp)){
44+
fs.mkdirSync(temp);
45+
}
46+
fs.writeFileSync(path.join(temp, 'branch_name.zip'), Buffer.from(download.data));
47+
48+
- name: Unzip branch name artifact
49+
run: unzip branch_name.zip -d "${{ runner.temp }}/artifacts"
50+
2151
- name: Trigger other workflows
2252
run: |
2353
for workflow in .github/workflows/*.yml; do
2454
if [[ ! " ${EXCLUDE_WORKFLOWS[@]} " =~ " $(basename $workflow) " ]]; then
25-
echo "Triggering workflow run $(basename $workflow)"
26-
gh workflow run $(basename $workflow)
55+
echo "Triggering workflow run $(basename $workflow) for $(cat ${{ runner.temp }}/artifacts/branch_name)"
56+
gh workflow run $(basename $workflow) --ref $(cat ${{ runner.temp }}/artifacts/branch_name)
2757
fi
2858
done

.github/workflows/phusion.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,15 @@ jobs:
9393
run: |
9494
docker buildx imagetools inspect \
9595
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
96+
97+
- name: Save branch name
98+
env:
99+
BRANCH: ${{ github.ref_name }}
100+
run: |
101+
mkdir -p ./branch
102+
echo $BRANCH > ./branch/branch_name
103+
104+
- uses: actions/upload-artifact@v4
105+
with:
106+
name: branch_name
107+
path: branch/

0 commit comments

Comments
 (0)