Skip to content

Commit

Permalink
Merge pull request #1 from dafyddj/feat/initial
Browse files Browse the repository at this point in the history
feat: initial version of `copier-github-action`
  • Loading branch information
dafyddj authored Apr 27, 2024
2 parents 0cf983e + 8af0be4 commit 8df641d
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: v2.0.5
_src_path: gh:dafyddj/copier-bootstrap
template_name: copier-github-action
31 changes: 31 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"enabledManagers": [
"custom.regex",
"git-submodules",
],
"extends": [
"config:recommended",
],
// `copier` template updates
// There are two conditions that we need to account for
// * a "clean" `.copier-answers.yml` file
// * update needed but not yet applied (and further updates could appear in this condition)
// `renovate` needs to be able to match both conditions for PRs to work properly
// We make a hacky use of the otherwise unused field `currentDigest` to hold the current copier template version
"customManagers": [
{
"customType": "regex",
"fileMatch": ["^.copier-answers.yml$"],
"matchStrings": [
"_commit: (?<currentValue>\\S+)\\n_src_path: gh:(?<depName>\\S+)\\n",
"_commit: (?<currentDigest>\\S+) # __copier_update_needed (?<currentValue>\\S+)\\n_src_path: gh:(?<depName>\\S+)\\n",
],
"datasourceTemplate": "github-tags",
"autoReplaceStringTemplate": "_commit: {{#if currentDigest}}{{{currentDigest}}}{{else}}{{{currentValue}}}{{/if}} # __copier_update_needed {{{newValue}}}\n_src_path: gh:{{{depName}}}\n",
},
],
"git-submodules": {
"enabled": true
},
}
62 changes: 62 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Test & release

on:
pull_request:
push:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}

jobs:
pre-commit:
name: Run `pre-commit`
runs-on: ubuntu-latest
env:
# renovate: datasource=github-releases depName=actions/python-versions extractVersion=^(?<version>\S+)-\d+$
PYTHON_VERSION: 3.12.3
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
test:
name: Run approval tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0 # `copier` prefers full-history clones
submodules: true
- name: Debug on runner (When re-run with "Enable debug logging" checked)
if: runner.debug
uses: mxschmitt/action-tmate@b3db6e16e597d92037c8647e54acc5d2b1b48dee # v3.18
with:
detached: true
- name: Install test dependencies
run: |
pipx install copier
pipx install texttest
- name: Run `texttest`
run: texttest -b
results:
name: Collect results
needs:
- pre-commit
- test
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: codfish/semantic-release-action@b0e57c976bf8f74b2454f59a30e4a1b5f11727b4 # v3.3.0
with:
plugins: |
[ "@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github"
]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "base"]
path = base
url = https://github.com/dafyddj/base-github-action
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
args: [--assume-in-merge]
- id: check-yaml
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.2
hooks:
- id: check-github-workflows
name: Check GitHub workflows with check-jsonschema
args: ["--verbose"]
- id: check-renovate
name: Check Renovate config with check-jsonschema
additional_dependencies: [json5==0.9.14]
args: ["--verbose"]
1 change: 1 addition & 0 deletions base
Submodule base added at 419a40
10 changes: 10 additions & 0 deletions bin/copier
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Check if the copier binary exists
if ! [ -x "$(command -v copier)" ]; then
echo "Error: 'copier' binary not found or not executable"
exit 1
fi

# Call the copier binary with all command line arguments
copier "$@"
2 changes: 2 additions & 0 deletions copier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_subdirectory: template
_templates_suffix: .copier-jinja
31 changes: 31 additions & 0 deletions template/.github/renovate.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"enabledManagers": [
"custom.regex",
"git-submodules",
],
"extends": [
"config:recommended",
],
// `copier` template updates
// There are two conditions that we need to account for
// * a "clean" `.copier-answers.yml` file
// * update needed but not yet applied (and further updates could appear in this condition)
// `renovate` needs to be able to match both conditions for PRs to work properly
// We make a hacky use of the otherwise unused field `currentDigest` to hold the current copier template version
"customManagers": [
{
"customType": "regex",
"fileMatch": ["^.copier-answers.yml$"],
"matchStrings": [
"_commit: (?<currentValue>\\S+)\\n_src_path: gh:(?<depName>\\S+)\\n",
"_commit: (?<currentDigest>\\S+) # __copier_update_needed (?<currentValue>\\S+)\\n_src_path: gh:(?<depName>\\S+)\\n",
],
"datasourceTemplate": "github-tags",
"autoReplaceStringTemplate": "_commit: {{#if currentDigest}}{{{currentDigest}}}{{else}}{{{currentValue}}}{{/if}} # __copier_update_needed {{{newValue}}}\n_src_path: gh:{{{depName}}}\n",
},
],
"git-submodules": {
"enabled": true
},
}
68 changes: 68 additions & 0 deletions template/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
name: Main
on: [push, pull_request]

jobs:
pre-commit:
name: Run `pre-commit`
runs-on: ubuntu-latest
env:
# renovate: datasource=github-tags depName=python/cpython
PYTHON_VERSION: 3.12.3
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
gv:
name: Get value
runs-on: ubuntu-latest
outputs:
value: ${{ steps.get-value.outputs.value }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- id: get-value
name: Run this action
uses: ./
- run: |
echo "::notice ::Value: ${{ steps.get-value.outputs.value }}"
show-value:
name: Show value
needs: gv
runs-on: ubuntu-latest
steps:
- run: |
echo "::notice ::Value: $VALUE"
env:
VALUE: ${{ fromJSON(needs.gv.outputs.value) }}
release:
name: Release
needs:
- pre-commit
- show-value
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Run `semantic-release`
uses: codfish/semantic-release-action@b0e57c976bf8f74b2454f59a30e4a1b5f11727b4 # v3.3.0
id: sem-rel
with:
plugins: |
[ "@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github"
]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update branch for major version
if: steps.sem-rel.outputs.new-release-published == 'true'
run: git push
https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
HEAD:refs/heads/v${{steps.sem-rel.outputs.release-major}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions template/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
args: [--assume-in-merge]
- id: check-yaml
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.2
hooks:
- id: check-github-workflows
name: Check GitHub workflows with check-jsonschema
args: ["--verbose"]
- id: check-renovate
name: Check Renovate config with check-jsonschema
additional_dependencies: [json5==0.9.14]
args: ["--verbose"]
17 changes: 17 additions & 0 deletions template/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Example
author: dafyddj
description: An example composite action
outputs:
value:
description: A basic output
value: ${{ steps.get-value.outputs.value }}
runs:
using: composite
steps:
- id: get-value
shell: bash
run: |
OUTPUT="value=true"
echo "Setting '$OUTPUT'"
echo "$OUTPUT" >> $GITHUB_OUTPUT
2 changes: 2 additions & 0 deletions template/{{ _copier_conf.answers_file }}.copier-jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
{{ _copier_answers|to_nice_yaml -}}
1 change: 1 addition & 0 deletions test/GenerateProject/action_yml.tt
9 changes: 9 additions & 0 deletions test/GenerateProject/catalogue.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The following new files/directories were created:
<Test Directory>
----.copier-answers.yml
----.github
--------renovate.json5
--------workflows
------------main.yml
----.pre-commit-config.yaml
----action.yml
1 change: 1 addition & 0 deletions test/GenerateProject/main_yml.tt
1 change: 1 addition & 0 deletions test/GenerateProject/options.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$TEXTTEST_ROOT/.. .
1 change: 1 addition & 0 deletions test/GenerateProject/pre-commit_yaml.tt
8 changes: 8 additions & 0 deletions test/GenerateProject/stderr.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/opt/homebrew/Cellar/copier/9.2.0/libexec/lib/python3.12/site-packages/copier/vcs.py:202: DirtyLocalWarning: Dirty template changes included automatically.
warn(

Copying from template version 0.0.0.post2.dev0+9966d43
 identical .
 create .copier-answers.yml
 create .github
 create .github/renovate.json5
2 changes: 2 additions & 0 deletions test/GenerateProject/stdout.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


25 changes: 25 additions & 0 deletions test/config.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Full path to the System Under Test (or Java Main Class name)
executable:${TEXTTEST_ROOT}/../bin/copier

# Naming scheme to use for files for stdin,stdout and stderr
filename_convention_scheme:standard

# Expanded name to use for application
full_name:copier-github-action

create_catalogues:true

[collate_file]
action_yml:action.yml
main_yml:.github/workflows/main.yml
pre-commit_yaml:.pre-commit-config.yaml

[run_dependent_text]
stderr:Copying from template version
stderr:DirtyLocalWarning{LINES 2}
stderr:No git tags found in template; using HEAD as ref
stderr:create
stderr:conflict
stderr:identical
stderr:overwrite
stderr:skip
1 change: 1 addition & 0 deletions test/options.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
copy --defaults --vcs-ref=HEAD
1 change: 1 addition & 0 deletions test/testsuite.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GenerateProject

0 comments on commit 8df641d

Please sign in to comment.