|
| 1 | +name: "Download ECL Watch Nightly" |
| 2 | +description: "Download the latest non-expired ECL Watch nightly artifact into a package build tree." |
| 3 | + |
| 4 | +inputs: |
| 5 | + destination: |
| 6 | + description: "Destination directory for the downloaded nightly dist files." |
| 7 | + required: true |
| 8 | + artifact-name: |
| 9 | + description: "Name of the ECL Watch nightly artifact." |
| 10 | + required: false |
| 11 | + default: eclwatch-nightly |
| 12 | + |
| 13 | +runs: |
| 14 | + using: "composite" |
| 15 | + steps: |
| 16 | + - name: Locate latest ECL Watch nightly |
| 17 | + id: nightly |
| 18 | + uses: actions/github-script@v8 |
| 19 | + env: |
| 20 | + NIGHTLY_ARTIFACT_NAME: ${{ inputs.artifact-name }} |
| 21 | + NIGHTLY_DESTINATION: ${{ inputs.destination }} |
| 22 | + with: |
| 23 | + github-token: ${{ github.token }} |
| 24 | + script: | |
| 25 | + const fs = require("fs"); |
| 26 | +
|
| 27 | + const artifactName = process.env.NIGHTLY_ARTIFACT_NAME; |
| 28 | + const destination = process.env.NIGHTLY_DESTINATION; |
| 29 | + const [owner, repo] = context.repo.owner && context.repo.repo |
| 30 | + ? [context.repo.owner, context.repo.repo] |
| 31 | + : "${{ github.repository }}".split("/"); |
| 32 | +
|
| 33 | + fs.rmSync(destination, { recursive: true, force: true }); |
| 34 | + fs.mkdirSync(destination, { recursive: true }); |
| 35 | +
|
| 36 | + const artifacts = await github.paginate(github.rest.actions.listArtifactsForRepo, { |
| 37 | + owner, |
| 38 | + repo, |
| 39 | + name: artifactName, |
| 40 | + per_page: 100 |
| 41 | + }); |
| 42 | +
|
| 43 | + const artifact = artifacts |
| 44 | + .filter(item => !item.expired && item.workflow_run?.id) |
| 45 | + .sort((left, right) => Date.parse(right.created_at) - Date.parse(left.created_at))[0]; |
| 46 | +
|
| 47 | + if (!artifact) { |
| 48 | + core.setFailed(`Unable to find a non-expired ${artifactName} artifact in ${owner}/${repo}.`); |
| 49 | + return; |
| 50 | + } |
| 51 | +
|
| 52 | + core.info(`Using ${artifactName} artifact ${artifact.id} from run ${artifact.workflow_run.id}, created ${artifact.created_at}.`); |
| 53 | + core.setOutput("run-id", String(artifact.workflow_run.id)); |
| 54 | +
|
| 55 | + - name: Download latest ECL Watch nightly |
| 56 | + uses: actions/download-artifact@v8 |
| 57 | + with: |
| 58 | + name: ${{ inputs.artifact-name }} |
| 59 | + path: ${{ inputs.destination }} |
| 60 | + repository: ${{ github.repository }} |
| 61 | + run-id: ${{ steps.nightly.outputs.run-id }} |
| 62 | + github-token: ${{ github.token }} |
0 commit comments