[github actions] Reusable workflows가 설치되어 있어서 대충 정리해봤어요.
13463 단어 GitHub ActionsCICDtech
연말에 이 기사 내용을 포함한github actions를 어떻게 재활용할 것인지 총결산했으니 함께 공유해 주세요!↓↓↓
이 보도에 관하여
2021/11/24 드디어 github actions에서 실현
Reusable workflows.우선, 나는 문서를 간단하게 복습하면서 요점을 정리하고 싶다.
도대체 뭐가 그리 좋으냐
지금까지의github actions는workflow에서action이라고 할 수 있지만workflow는다른workflow라고 할 수 없습니다.
워크플로우가 하나면 문제가 되지 않지만, 같은 워크플로우의 기술을 반복해서 사용하려면 문제가 된다.
예를 들어 여러 창고에서 다음과 같은workflow를 사용할 때
actions/checkout@v2와 actions/setup-node@v2의 순서, 사용된 버전, 파라미터 등이 같고 각 창고에서만 각각 기술할 수 있다.사용하는 버전이 변경되면 모든 창고에 반영하려면 모든 창고에 대해 횡적 홍보를 해야 하기 때문에 매우 복잡해진다고 생각합니다.
example.yaml
jobs:
example:
name: example job
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: 14.x
registry-url: "xxxxxxxxx"
scope: "@xxxxxxxxxx"
...
이번 실장으로 워크플로우 수준이 공통화되고 통일 관리도 쉬워진 것이 기쁘다.문서를 대강 정리하다
마음에 드는 부분을 총결산하다.아래의 문서에는 모두 제목이 있으니 관심 있는 사람은 깊이 파헤쳐 주십시오.
Overview
caller workflow, 호출자는called workflow이라고 부른다.called workflow는 caller workflow의context로 처리되기 때문에 called workflow에서action을 사용했음에도 불구하고 checkkout은 actions/checkout창고에 사용되었다.caller workflow 중called workflow의caller workflow의context도 계승되기 때문에 github로 만류할 수 있다.secrets.GITHUB_TOKEN의caller workflow 사용을 할 수 없기 때문에 주의해야 한다.env는 called workflow에 기술해야 한다workflow_call.on의 처리 방법을 깨닫지 못하면 반할 것 같아요.Access to reusable workflows
Limitations
env에서 다른workflow를 호출할 수 없습니다.Example reusable workflow
재사용된workflow의 경우
called workflow에 기술해야 한다.on.workflow_call,inputs,outputs 등workflow 전체와 관련된 정의는secrets 이하이다.Job의 작법은 별다른 변화가 없는 것 같다.(후술한
on.workflow_call 주변 제외)reusable_workflow.yaml
name: Reusable workflow example
on:
workflow_call:
inputs:
username:
required: true
type: string
secrets:
token:
required: true
jobs:
example_job:
name: Pass input and secrets to my-action
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/my-action@v1
with:
username: ${{ inputs.username }}
token: ${{ secrets.token }}
Calling a reusable workflow
액션을 사용한 것과 같은 기술은
output에 기술한 것이 아니라 steps.foo.uses에 기술한 점과 다르다.jobs.foo.uses 아래에 사용된 버전은 branch,commiit hash를 설명하는 점과 @에 파라미터를 제출하는 action과 같습니다.caller_workflow.yaml
name: Call a reusable workflow
on:
pull_request:
branches:
- main
jobs:
call-workflow:
uses: octo-org/example-repo/.github/workflows/workflow-A.yml@v1
call-workflow-passing-data:
uses: octo-org/example-repo/.github/workflows/workflow-B.yml@main
with:
username: mona
secrets:
token: ${{ secrets.TOKEN }}
Using outputs from a reusable workflow
reusable workflow에서 반환 값을 받으려면
with이렇게 전달하는 구조.output.yaml
name: Reusable workflow
on:
workflow_call:
# Map the workflow outputs to job outputs
outputs:
firstword:
description: "The first output string"
value: ${{ jobs.example_job.outputs.output1 }}
secondword:
description: "The second output string"
value: ${{ jobs.example_job.outputs.output2 }}
jobs:
example_job:
name: Generate output
runs-on: ubuntu-latest
# Map the job outputs to step outputs
outputs:
output1: ${{ steps.step1.outputs.firstword }}
output2: ${{ steps.step2.outputs.secondword }}
steps:
- id: step1
run: echo "::set-output name=firstword::hello"
- id: step2
run: echo "::set-output name=secondword::world"
총결산
privte repository의reusable workflow를 다른 repository에 사용할 수 있을지 궁금해요.
Repository에 대한 Reusable workflow 사용 추기
stepのoutput -> jobのoutput -> workflowのoutput와 마찬가지로 action 재활용을 시도했지만 안 돼요.아래의 오류 정보는 상당히 의도적인 동작으로 보이기 때문에 지금은 사용할 수 없습니다.(창고 이름이 적절하게 바뀝니다)
error parsing called workflow "xxxx": Workflows in 'xxxx' cannot access remote workflows in 'xxxx'. See https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#access-to-reusable-workflows for more information.
Reference
이 문제에 관하여([github actions] Reusable workflows가 설치되어 있어서 대충 정리해봤어요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/jerome/articles/618af7cc934f2f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)