diff --git a/.github/actions/download-artifact/action.yml b/.github/actions/download-artifact/action.yml new file mode 100644 index 0000000..f97c3c0 --- /dev/null +++ b/.github/actions/download-artifact/action.yml @@ -0,0 +1,39 @@ +--- +name: Download Artifact +description: Download artifact from the same or different workflow + +inputs: + name: + description: Artifact to be downloaded + required: true + type: string + +runs: + using: composite + steps: + - name: Download Artifact + uses: actions/github-script@v6 + with: + script: | + var inputs = ${{ toJSON(inputs) }} + var artifactName = inputs['name'] + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == artifactName + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data)); + + - name: 'Unzip artifact' + run: unzip ${{ inputs.name }}.zip + shell: bash diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index f3ecfd3..05ddf53 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -11,9 +11,6 @@ permissions: id-token: write jobs: build: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -39,28 +36,9 @@ jobs: # Action to download artifacts from a different workflow (analysis.yml) - name: 'Download artifact' if: ${{ github.event.workflow_run.conclusion == 'success' }} - uses: actions/github-script@v6 + uses: ./.github/actions/download-artifact with: - script: | - let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name == "Figures" - })[0]; - let download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - let fs = require('fs'); - fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/Figures.zip`, Buffer.from(download.data)); - - - name: 'Unzip artifact' - run: unzip Figures.zip + name: 'Figures' - name: Build html run: | @@ -75,6 +53,14 @@ jobs: with: path: 'docs/_build/html' + deploy: + needs: build + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4