Skip to content

Commit 380fc95

Browse files
author
a.pirogov
committed
distinguish repo branches in deployment script
1 parent cb0fa5d commit 380fc95

1 file changed

Lines changed: 63 additions & 23 deletions

File tree

.github/workflows/deploy_demo.yml

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,93 @@ on: [workflow_dispatch, workflow_call]
44

55
jobs:
66
deploy:
7-
if: github.event_name == 'push'
7+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
8+
89
runs-on: ubuntu-latest
910
steps:
1011

11-
- name: Checkout template repo
12-
uses: actions/checkout@v3
12+
- uses: actions/setup-python@v4
1313
with:
14-
path: fair-python-cookiecutter
14+
python-version: "3.10"
1515

16-
- name: Prepare SSH
16+
- name: Set git author (needed for commits)
17+
run: |
18+
git config --global user.email "deploy-fair-python-cookiecutter@example.com"
19+
git config --global user.name "Deployment Bot"
20+
21+
- name: Prepare SSH (needed for remote push)
1722
uses: webfactory/ssh-agent@v0.7.0
1823
with:
1924
# NOTE: generated private key, stored repo secret
2025
# (matching public key is registered Deployment Key in target Github repo)
2126
ssh-private-key: ${{ secrets.SSH_DEPLOY_KEY }}
2227

23-
- name: Set git author
24-
run: |
25-
git config --global user.email "deploy-fair-python-cookiecutter@example.com"
26-
git config --global user.name "Deployment Bot"
28+
# ----
2729

28-
- uses: actions/setup-python@v4
30+
- name: Checkout template repo
31+
uses: actions/checkout@v3
2932
with:
30-
python-version: "3.10"
33+
path: fair-python-cookiecutter
3134

32-
- name: Install poetry
33-
run: pipx install poetry
35+
- name: Get current template version
36+
run: |
37+
TEMPLATE_DIR="./fair-python-cookiecutter"
3438
35-
- name: Install cookiecutter
36-
run: pip install cookiecutter==2.1.1
39+
QUOTED_VERSION=$(grep -e "^version" $TEMPLATE_DIR/pyproject.toml | sed 's/^.*=//')
40+
TEMPLATE_VERSION=$(echo "$QUOTED_VERSION" | sed 's/"//g' | xargs)
41+
echo "extracted template version:" $TEMPLATE_VERSION
3742
38-
- name: Prepare cookiecutter configuration
43+
echo "FAIR_TEMPLATE_DIR=$TEMPLATE_DIR" >> "$GITHUB_ENV"
44+
echo "FAIR_TEMPLATE_VERSION=$TEMPLATE_VERSION" >> "$GITHUB_ENV"
45+
46+
- name: Prepare demo repository cookiecutter config
3947
run: |
40-
TEMPLATE_VERSION=$(grep -e "^version" ./fair-python-cookiecutter/pyproject.toml | sed 's/^.*=//')
41-
echo "extracted template version:" $TEMPLATE_VERSION
4248
SED_CMD_PREF='s/\(^.*version:\).*/\1'
43-
SED_CMD="${SED_CMD_PREF}${TEMPLATE_VERSION}/"
49+
SED_CMD="${SED_CMD_PREF} \"${FAIR_TEMPLATE_VERSION}\"/"
50+
TEMPLATE_CONFIG=cconf.yaml
51+
4452
echo "running sed to insert version:" $SED_CMD
45-
sed "$SED_CMD" ./fair-python-cookiecutter/tests/demo.yaml > cconf.yaml
53+
sed "$SED_CMD" $FAIR_TEMPLATE_DIR/tests/demo.yaml > $TEMPLATE_CONFIG
54+
4655
echo "resulting repo cookiecutter configuration:"
47-
cat cconf.yaml
56+
cat $TEMPLATE_CONFIG
57+
58+
echo "FAIR_TEMPLATE_CONFIG=$TEMPLATE_CONFIG" >> "$GITHUB_ENV"
59+
60+
# ----
61+
62+
- name: Install poetry
63+
run: pipx install poetry
64+
65+
- name: Install cookiecutter
66+
run: pip install cookiecutter==2.1.1
4867

4968
- name: Instantiate demo repository
50-
run: cookiecutter ./fair-python-cookiecutter --no-input --config-file=cconf.yaml
69+
run: cookiecutter $FAIR_TEMPLATE_DIR --no-input --config-file=$FAIR_TEMPLATE_CONFIG
70+
71+
# ----
72+
73+
- name: Get branch triggering the workflow
74+
run: |
75+
BRANCH="$(echo ${GITHUB_REF##*/})"
76+
echo "ci branch:" $BRANCH
77+
echo "CI_BRANCH=$BRANCH" >> "$GITHUB_ENV"
5178
5279
- name: Deploy generated repository
5380
run: |
5481
cd fair-python-cookiecutter-demo
5582
git remote add origin git@github.com:Materials-Data-Science-and-Informatics/fair-python-cookiecutter-demo.git
56-
git push -f --set-upstream origin main
83+
84+
if [ "$CI_BRANCH" != "main" ]; then
85+
git branch -m main $CI_BRANCH
86+
git status
87+
fi
88+
89+
git push -f --set-upstream origin $CI_BRANCH
90+
91+
# - name: Push tag
92+
# # TODO: uncomment once it works
93+
# # if: startswith(github.ref, 'refs/tags/v')
94+
# run: |
95+
# cd fair-python-cookiecutter-demo
96+
# # git tag "v$FAIR_TEMPLATE_VERSION"

0 commit comments

Comments
 (0)