From f71ebd80deec649460974cafef9306c8577ba73e Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Thu, 1 Aug 2024 10:53:46 +0100 Subject: [PATCH] add CI to deploy ioc-template-example --- .github/workflows/_check.yml | 27 +++++++++++++++++++++++++++ .github/workflows/_example.yml | 34 ++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 16 ++++++++++++++++ example-answers.yml | 9 +++++++++ 4 files changed, 86 insertions(+) create mode 100644 .github/workflows/_check.yml create mode 100644 .github/workflows/_example.yml create mode 100644 .github/workflows/ci.yml create mode 100644 example-answers.yml diff --git a/.github/workflows/_check.yml b/.github/workflows/_check.yml new file mode 100644 index 0000000..a6139c1 --- /dev/null +++ b/.github/workflows/_check.yml @@ -0,0 +1,27 @@ +on: + workflow_call: + outputs: + branch-pr: + description: The PR number if the branch is in one + value: ${{ jobs.pr.outputs.branch-pr }} + +jobs: + pr: + runs-on: "ubuntu-latest" + outputs: + branch-pr: ${{ steps.script.outputs.result }} + steps: + - uses: actions/github-script@v7 + id: script + if: github.event_name == 'push' + with: + script: | + const prs = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + head: context.repo.owner + ':${{ github.ref_name }}' + }) + if (prs.data.length) { + console.log(`::notice ::Skipping CI on branch push as it is already run in PR #${prs.data[0]["number"]}`) + return prs.data[0]["number"] + } diff --git a/.github/workflows/_example.yml b/.github/workflows/_example.yml new file mode 100644 index 0000000..9b2f135 --- /dev/null +++ b/.github/workflows/_example.yml @@ -0,0 +1,34 @@ +on: + workflow_call: + secrets: + EXAMPLE_DEPLOY_KEY: + required: true +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # Need this to get version number from last tag + fetch-depth: 0 + + - name: Regenerate example + run: | + pipx run copier copy --data-file example-answers.yml --trust --vcs-ref=HEAD . example + + - name: Rewrite copier answers + run: | + sed -i 's|_src_path: .|_src_path: gh:epics-containers/ioc-template|' example/.copier-answers.yml + + - name: Publish example + # We pin to the SHA, not the tag, for security reasons. + # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions + uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 + with: + deploy_key: ${{ secrets.EXAMPLE_DEPLOY_KEY }} + publish_dir: example + external_repository: epics-containers/ioc-template-example + publish_branch: main + exclude_assets: '' # default would exclude .github diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..19c4d8d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,16 @@ +name: CI + +on: + push: + pull_request: + +jobs: + check: + uses: ./.github/workflows/_check.yml + + example: + needs: test + if: github.ref_name == 'main' + uses: ./.github/workflows/_example.yml + secrets: + EXAMPLE_DEPLOY_KEY: ${{ secrets.EXAMPLE_DEPLOY_KEY }} diff --git a/example-answers.yml b/example-answers.yml new file mode 100644 index 0000000..80d78ad --- /dev/null +++ b/example-answers.yml @@ -0,0 +1,9 @@ +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +_commit: 3.5.0 +_src_path: ioc-template +description: A test instantiation of the ioc-template copier template +git_platform: github.com +github_org: epics-containers +name: ioc-template-example +repo_uri: git@github.com:epics-containers/ioc-template-example.git +rtems: false