-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #545 from AmadeusITGroup/ci/external-publish-pr
ci: publish-pr on external workflow
- Loading branch information
Showing
5 changed files
with
118 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Publish PR | ||
|
||
on: | ||
workflow_run: | ||
workflows: ['Main CI'] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
version: | ||
if: ${{ github.event.workflow_run.event == 'pull_request' }} | ||
permissions: | ||
actions: read | ||
runs-on: ubuntu-latest | ||
outputs: | ||
nextVersionTag: ${{ steps.newVersion.outputs.nextVersionTag }} | ||
steps: | ||
- name: get logs from workflow run | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
let download = await github.rest.actions.downloadWorkflowRunLogs({ | ||
...context.repo, | ||
run_id: context.payload.workflow_run.id, | ||
}); | ||
let fs = require('fs'); | ||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/logs.zip`, Buffer.from(download.data)); | ||
- run: unzip logs.zip | ||
- name: extract version from logs | ||
id: newVersion | ||
run: echo nextVersionTag=$(find *_version.txt | xargs grep -hiPo '(?<=nextVersionTag variable has been set with ).*$') >> "$GITHUB_OUTPUT" | ||
|
||
publish-packages-pr: | ||
uses: ./.github/workflows/publish.yml | ||
needs: [version] | ||
permissions: | ||
packages: write | ||
contents: read | ||
secrets: inherit | ||
with: | ||
version: ${{ needs.version.outputs.nextVersionTag }} | ||
prerelease: true | ||
isPullRequest: true | ||
|
||
notify-parent: | ||
runs-on: ubuntu-latest | ||
needs: [publish-packages-pr] | ||
if: success() || failure() | ||
permissions: | ||
checks: write | ||
steps: | ||
- name: Update triggering workflow | ||
uses: actions/github-script@v6 | ||
env: | ||
PUBLISH_RESULT: ${{ needs.publish-packages-pr.result }} | ||
with: | ||
script: | | ||
const backUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/attempts/${context.runAttempt || 1}`; | ||
await github.rest.checks.create({ | ||
...context.repo, | ||
head_sha: context.payload.workflow_run.head_commit.id, | ||
name: 'publish-packages-pr', | ||
conclusion: process.env.PUBLISH_RESULT, | ||
status: 'completed', | ||
output: { | ||
title: 'publish-packages-pr', | ||
summary: `${process.env.PUBLISH_RESULT} publish [${backUrl}](${backUrl})` | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
name: Download Build Output | ||
description: Download and restore the `dist` folders from github artifact (check ../upload-build-output) | ||
inputs: | ||
artifactName: | ||
description: Name of the artifact on which the outputs are published | ||
default: dist | ||
required: false | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: actions/download-artifact@v3 | ||
if: github.event_name != 'workflow_run' | ||
with: | ||
name: dist | ||
name: ${{ inputs.artifactName }} | ||
path: '.' | ||
- run: unzip -q -n dist.zip | ||
|
||
- name: 'Download artifact' | ||
uses: actions/github-script@v6 | ||
if: github.event_name == 'workflow_run' | ||
with: | ||
script: | | ||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | ||
...context.repo, | ||
run_id: context.payload.workflow_run.id, | ||
}); | ||
let matchArtifact = allArtifacts.data.artifacts.find((artifact) => artifact.name === '${{ inputs.artifactName }}'); | ||
if (!matchArtifact) { | ||
throw new Error('Could not find an artifact with name "${{ inputs.artifactName }}" for workflow_run ${context.payload.workflow_run.id}'); | ||
} | ||
let download = await github.rest.actions.downloadArtifact({ | ||
...context.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
let fs = require('fs'); | ||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${{ inputs.artifactName }}.zip`, Buffer.from(download.data)); | ||
- run: unzip -q -n ${{ inputs.artifactName }}.zip | ||
shell: bash | ||
- run: rm -f dist.zip | ||
- run: rm -f ${{ inputs.artifactName }}.zip | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
name: Upload Build Output | ||
description: Upload a github artifact containing all `dist` outputs | ||
inputs: | ||
artifactName: | ||
description: Name of the artifact on which the outputs are published | ||
default: dist | ||
required: false | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- run: zip -q -r dist.zip . -i "apps/*/dist/*" "packages/*/dist/*" -x "*/node_modules/*" ".cache/*" | ||
- run: zip -q -r ${{ inputs.artifactName }}.zip . -i "apps/*/dist/*" "packages/*/dist/*" -x "*/node_modules/*" ".cache/*" | ||
shell: bash | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist.zip | ||
- run: rm -f dist.zip | ||
name: ${{ inputs.artifactName }} | ||
path: ${{ inputs.artifactName }}.zip | ||
- run: rm -f ${{ inputs.artifactName }}.zip | ||
shell: bash |