Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 3c04dcc

Browse files
authored
Merge pull request #1 from iamamutt/main
Changes for gh-actions to build content
2 parents 0db8948 + 7677ed8 commit 3c04dcc

File tree

5 files changed

+259
-15
lines changed

5 files changed

+259
-15
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: bake-cookies
2+
author: Joseph Burling
3+
description: "Build cookiecutter content and push to branch."
4+
5+
inputs:
6+
github_token:
7+
description: "GitHub token"
8+
required: true
9+
10+
build_branch:
11+
description: "Branch name that holds the generated content"
12+
required: false
13+
default: build
14+
15+
folder:
16+
description: "Subdirectory for a specific template"
17+
required: true
18+
19+
cookiecutter_pkg:
20+
description: "Cookiecutter package string for pip install"
21+
required: false
22+
default: "cookiecutter"
23+
24+
cookiecutter_args:
25+
description: "Arguments passed to cookiecutter"
26+
required: false
27+
default: "-vf --no-input"
28+
29+
new_tag:
30+
description: "Tag used during commit"
31+
required: false
32+
default: ""
33+
34+
runs:
35+
using: composite
36+
steps:
37+
- name: "Configure git"
38+
run: |
39+
echo "${{ github.action_path }}" >> $GITHUB_PATH
40+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
41+
git config --global user.name "github-actions[bot]"
42+
shell: bash
43+
44+
- name: "Setup Python"
45+
uses: actions/setup-python@v2
46+
with:
47+
python-version: "3.10"
48+
49+
- name: Generate Default 'cookiecutter' Content
50+
run: |
51+
pip install -U ${{ inputs.cookiecutter_pkg }}
52+
rm -rf ./.build
53+
cookiecutter ${{ inputs.cookiecutter_args }} -o ./.build/ .
54+
shell: bash
55+
56+
- name: Upload Artifact Content
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: cookiecutter_content_${{ inputs.new_tag }}
60+
path: .build/${{ inputs.folder }}
61+
62+
- name: Create 'build' Branch
63+
id: create-new-branch-step
64+
run: |
65+
branch_exists=$(git ls-remote --heads origin ${{ inputs.build_branch }})
66+
last_ref=${{ github.ref_name }}
67+
if [[ -z ${branch_exists} ]]; then
68+
echo "Creating the branch '${{ inputs.build_branch }}' from '$last_ref'"
69+
(
70+
git switch --orphan ${{ inputs.build_branch }}
71+
git commit --allow-empty -m "ci(bot): initializing orphaned branch"
72+
git push -u origin ${{ inputs.build_branch }}
73+
)
74+
git switch $last_ref
75+
echo "::debug::Finished creating the branch '${{ inputs.build_branch }}'"
76+
else
77+
echo "Branch '${{ inputs.build_branch }}' already exists"
78+
fi
79+
shell: bash
80+
81+
- name: Checkout 'build' Branch
82+
uses: actions/checkout@v3
83+
with:
84+
path: ${{ inputs.build_branch }}
85+
ref: ${{ inputs.build_branch }}
86+
fetch-depth: 0
87+
88+
- name: Cleaning Previous Output Folder
89+
run: rm -rf "${{ inputs.folder }}"
90+
working-directory: ${{ inputs.build_branch }}
91+
shell: bash
92+
93+
- name: Downloading Artifact Content
94+
uses: actions/download-artifact@v3
95+
with:
96+
name: cookiecutter_content_${{ inputs.new_tag }}
97+
path: ${{ inputs.build_branch }}/${{ inputs.folder }}
98+
99+
- name: Copying Built Content to Branch
100+
run: |
101+
(
102+
cd "${{ inputs.folder }}"
103+
git add . --force
104+
)
105+
echo "Checking if there's something to commit."
106+
if [ -z "$(git status --porcelain)" ]; then
107+
echo "Nothing to commit."
108+
exit 0
109+
fi
110+
echo "Committing and pushing:"
111+
git status --porcelain
112+
git commit -m "ci(generate-defaults): copying cookiecutter content ${{ inputs.new_tag }}"
113+
git push origin HEAD:${{ inputs.build_branch }} --force --follow-tags
114+
working-directory: ${{ inputs.build_branch }}
115+
shell: bash
116+
117+
branding:
118+
icon: "aperture"
119+
color: "blue"

.github/workflows/ci.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: run-ci-jobs
2+
3+
on:
4+
push:
5+
branches: ["main", "flit"]
6+
7+
jobs:
8+
get_tag:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
new_tag: ${{ steps.tag_version.outputs.new_tag }}
12+
changelog: ${{ steps.tag_version.outputs.changelog }}
13+
steps:
14+
- name: Checkout Repository
15+
uses: actions/checkout@v3
16+
17+
- name: Create a tag
18+
uses: mathieudutour/[email protected]
19+
id: tag_version
20+
with:
21+
github_token: ${{ secrets.GITHUB_TOKEN }}
22+
release_branches: main,flit
23+
create_annotated_tag: false
24+
fetch_all_tags: true
25+
26+
generate_flit_content:
27+
runs-on: ubuntu-latest
28+
needs: get_tag
29+
if: |
30+
always() &&
31+
(needs.get_tag.result == 'success') &&
32+
(github.ref_name == 'flit') &&
33+
(github.ref_type == 'branch')
34+
steps:
35+
- name: Checkout Repository for Local Action
36+
uses: actions/checkout@v3
37+
38+
- name: Generate Content from 'flit' Template
39+
id: bake-cookies
40+
uses: ./.github/actions/bake-cookies
41+
with:
42+
github_token: ${{ secrets.GITHUB_TOKEN }}
43+
folder: o-science-institute_w-neuro-lab
44+
cookiecutter_pkg: git+https://github.com/cookiecutter/cookiecutter
45+
cookiecutter_args: -f --no-input
46+
new_tag: ${{ needs.get_tag.outputs.new_tag }}
47+
48+
generate_workflow_content:
49+
runs-on: ubuntu-latest
50+
needs: [get_tag]
51+
if: |
52+
always() &&
53+
(needs.get_tag.result == 'success') &&
54+
(github.ref_name == 'main') &&
55+
(github.ref_type == 'branch')
56+
steps:
57+
- name: Checkout Repository for Local Action
58+
uses: actions/checkout@v3
59+
60+
- name: Generate Content from 'workflow' Template
61+
id: bake-cookies
62+
uses: ./.github/actions/bake-cookies
63+
with:
64+
github_token: ${{ secrets.GITHUB_TOKEN }}
65+
folder: workflow_name
66+
cookiecutter_args: -f --no-input --directory workflow
67+
new_tag: ${{ needs.get_tag.outputs.new_tag }}
68+
69+
generate_element_content:
70+
runs-on: ubuntu-latest
71+
needs: [get_tag, generate_workflow_content]
72+
if: |
73+
always() &&
74+
(needs.get_tag.result == 'success') &&
75+
(needs.generate_workflow_content.result == 'success') &&
76+
(github.ref_name == 'main') &&
77+
(github.ref_type == 'branch')
78+
steps:
79+
- run: echo "Element template not yet available"
80+
# - name: Checkout Repository for Local Action
81+
# uses: actions/checkout@v3
82+
83+
# - name: Generate Content from 'element' Template
84+
# id: bake-cookies
85+
# uses: ./.github/actions/bake-cookies
86+
# with:
87+
# github_token: ${{ secrets.GITHUB_TOKEN }}
88+
# folder: element_name
89+
# cookiecutter_args: -f --no-input --directory element
90+
# new_tag: ${{ needs.get_tag.outputs.new_tag }}
91+
92+
make_release:
93+
runs-on: ubuntu-latest
94+
needs: [get_tag, generate_flit_content, generate_element_content]
95+
if: |
96+
always() &&
97+
(needs.get_tag.result == 'success') &&
98+
(
99+
needs.generate_flit_content.result == 'success' ||
100+
needs.generate_element_content.result == 'success'
101+
)
102+
steps:
103+
- name: Checkout Repository
104+
uses: actions/checkout@v3
105+
106+
- name: Downloading Artifact Content
107+
uses: actions/download-artifact@v3
108+
with:
109+
name: cookiecutter_content_${{ needs.get_tag.outputs.new_tag }}
110+
path: cookiecutter_content
111+
112+
- run: tar -zcf cookiecutter_content_${{ github.ref_name }}_${{ needs.get_tag.outputs.new_tag }}.tar.gz cookiecutter_content
113+
114+
- name: Create a Release
115+
uses: ncipollo/release-action@v1
116+
with:
117+
token: ${{ secrets.GITHUB_TOKEN }}
118+
tag: ${{ needs.get_tag.outputs.new_tag }}
119+
name: ${{ github.ref_name }}-release ${{ needs.get_tag.outputs.new_tag }}
120+
body: ${{ needs.get_tag.outputs.changelog }}
121+
allowUpdates: true
122+
generateReleaseNotes: true
123+
artifacts: "cookiecutter_content_${{ github.ref_name }}_${{ needs.get_tag.outputs.new_tag }}.tar.gz"

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,6 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
.DS_Store
131+
.DS_Store
132+
*.code-workspace
133+
.build/

element/cookiecutter.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"author_name": "DataJoint",
33
"author_email": "[email protected]",
4-
"project_name": "project name",
4+
"project_name": "element name",
55
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_')}}",
66
"license": [
7-
"MIT license",
8-
"BSD license",
9-
"ISC license",
10-
"Apache Software License 2.0",
11-
"GNU General Public License v3",
7+
"MIT license",
8+
"BSD license",
9+
"ISC license",
10+
"Apache Software License 2.0",
11+
"GNU General Public License v3",
1212
"GNU Lesser General Public License v3.0",
1313
"No license"
1414
]
15-
}
15+
}

workflow/cookiecutter.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"author_name": "DataJoint",
33
"author_email": "[email protected]",
4-
"project_name": "project name",
4+
"project_name": "workflow name",
55
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_')}}",
66
"license": [
7-
"MIT license",
8-
"BSD license",
9-
"ISC license",
10-
"Apache Software License 2.0",
11-
"GNU General Public License v3",
7+
"MIT license",
8+
"BSD license",
9+
"ISC license",
10+
"Apache Software License 2.0",
11+
"GNU General Public License v3",
1212
"GNU Lesser General Public License v3.0",
1313
"No license"
1414
]
15-
}
15+
}

0 commit comments

Comments
 (0)