-
Notifications
You must be signed in to change notification settings - Fork 5
101 lines (76 loc) · 3.25 KB
/
deploy_demo.yml
File metadata and controls
101 lines (76 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Deploy the demo repository
on: [workflow_dispatch, workflow_call]
jobs:
deploy:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Set git author (needed for commits)
run: |
git config --global user.email "deploy-fair-python-cookiecutter@example.com"
git config --global user.name "Deployment Bot"
git config --global init.defaultBranch main
- name: Prepare SSH (needed for remote push)
uses: webfactory/ssh-agent@v0.7.0
with:
# NOTE: generated private key, stored repo secret
# (matching public key is registered Deployment Key in target Github repo)
ssh-private-key: ${{ secrets.SSH_DEPLOY_KEY }}
# ----
- name: Checkout template repo
uses: actions/checkout@v3
with:
path: fair-python-cookiecutter
- name: Get current template version
run: |
TEMPLATE_DIR="./fair-python-cookiecutter"
QUOTED_VERSION=$(grep -e "^version" $TEMPLATE_DIR/pyproject.toml | sed 's/^.*=//')
TEMPLATE_VERSION=$(echo "$QUOTED_VERSION" | sed 's/"//g' | xargs)
echo "extracted template version:" $TEMPLATE_VERSION
echo "FAIR_TEMPLATE_DIR=$TEMPLATE_DIR" >> "$GITHUB_ENV"
echo "FAIR_TEMPLATE_VERSION=$TEMPLATE_VERSION" >> "$GITHUB_ENV"
- name: Prepare demo repository cookiecutter config
run: |
SED_CMD_PREF='s/\(^.*version:\).*/\1'
SED_CMD="${SED_CMD_PREF} \"${FAIR_TEMPLATE_VERSION}\"/"
TEMPLATE_CONFIG=cconf.yaml
echo "running sed to insert version:" $SED_CMD
sed "$SED_CMD" $FAIR_TEMPLATE_DIR/tests/demo.yaml > $TEMPLATE_CONFIG
echo "resulting repo cookiecutter configuration:"
cat $TEMPLATE_CONFIG
echo "FAIR_TEMPLATE_CONFIG=$TEMPLATE_CONFIG" >> "$GITHUB_ENV"
# ----
- name: Install poetry
run: pipx install poetry
- name: Install fair-python-cookiecutter (from local copy)
run: pip install "./$FAIR_TEMPLATE_DIR"
- name: Instantiate demo repository
run: fair-python-cookiecutter --no-input --config-file=$FAIR_TEMPLATE_CONFIG --repo-url=https://github.com/Materials-Data-Science-and-Informatics/fair-python-cookiecutter-demo
# ----
- name: Get branch triggering the workflow
run: |
BRANCH="$(echo ${GITHUB_REF##*/})"
if [[ $BRANCH == v*.*.* ]]; then
BRANCH=main # tagged release -> main branch
fi
echo "ci branch:" $BRANCH
echo "CI_BRANCH=$BRANCH" >> "$GITHUB_ENV"
- name: Deploy generated repository
run: |
cd fair-python-cookiecutter-demo
git remote add origin git@github.com:Materials-Data-Science-and-Informatics/fair-python-cookiecutter-demo.git
if [ "$CI_BRANCH" != "main" ]; then
# rename branch to desired target
git branch -m main $CI_BRANCH
git status
fi
git push -f --set-upstream origin $CI_BRANCH
- name: Push tag (to trigger release workflow in demo)
if: startswith(github.ref, 'refs/tags/v')
run: |
cd fair-python-cookiecutter-demo
git tag "v$FAIR_TEMPLATE_VERSION"
git push --tags origin $CI_BRANCH