Skip to content

Commit 2dc8e9a

Browse files
authored
Merge pull request #61 from AhmedBasem20/refactor-pipelines
Refactor the docs workflow
2 parents 5fe5728 + d22612c commit 2dc8e9a

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Download Artifact
3+
description: Download artifact from the same or different workflow
4+
5+
inputs:
6+
name:
7+
description: Artifact to be downloaded
8+
required: true
9+
type: string
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Download Artifact
15+
uses: actions/github-script@v6
16+
with:
17+
script: |
18+
var inputs = ${{ toJSON(inputs) }}
19+
var artifactName = inputs['name']
20+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
run_id: context.payload.workflow_run.id,
24+
});
25+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
26+
return artifact.name == artifactName
27+
})[0];
28+
let download = await github.rest.actions.downloadArtifact({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
artifact_id: matchArtifact.id,
32+
archive_format: 'zip',
33+
});
34+
let fs = require('fs');
35+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data));
36+
37+
- name: 'Unzip artifact'
38+
run: unzip ${{ inputs.name }}.zip
39+
shell: bash

.github/workflows/documentation.yml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ permissions:
1111
id-token: write
1212
jobs:
1313
build:
14-
environment:
15-
name: github-pages
16-
url: ${{ steps.deployment.outputs.page_url }}
1714
runs-on: ubuntu-latest
1815
steps:
1916
- uses: actions/checkout@v4
@@ -39,28 +36,9 @@ jobs:
3936
# Action to download artifacts from a different workflow (analysis.yml)
4037
- name: 'Download artifact'
4138
if: ${{ github.event.workflow_run.conclusion == 'success' }}
42-
uses: actions/github-script@v6
39+
uses: ./.github/actions/download-artifact
4340
with:
44-
script: |
45-
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
46-
owner: context.repo.owner,
47-
repo: context.repo.repo,
48-
run_id: context.payload.workflow_run.id,
49-
});
50-
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
51-
return artifact.name == "Figures"
52-
})[0];
53-
let download = await github.rest.actions.downloadArtifact({
54-
owner: context.repo.owner,
55-
repo: context.repo.repo,
56-
artifact_id: matchArtifact.id,
57-
archive_format: 'zip',
58-
});
59-
let fs = require('fs');
60-
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/Figures.zip`, Buffer.from(download.data));
61-
62-
- name: 'Unzip artifact'
63-
run: unzip Figures.zip
41+
name: 'Figures'
6442

6543
- name: Build html
6644
run: |
@@ -75,6 +53,14 @@ jobs:
7553
with:
7654
path: 'docs/_build/html'
7755

56+
deploy:
57+
needs: build
58+
environment:
59+
name: github-pages
60+
url: ${{ steps.deployment.outputs.page_url }}
61+
62+
runs-on: ubuntu-latest
63+
steps:
7864
- name: Deploy to GitHub Pages
7965
id: deployment
8066
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)