-
Notifications
You must be signed in to change notification settings - Fork 44
169 lines (145 loc) · 5.74 KB
/
ci_cd_updated_master.yml
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: CI/CD - New updates to `master`
on:
push:
branches:
- master
env:
DEFAULT_REPO_BRANCH: master
GIT_USER_NAME: OPTIMADE Developers
GIT_USER_EMAIL: "[email protected]"
jobs:
deploy_docs:
name: Deploy `latest` documentation
if: github.repository_owner == 'Materials-Consortia'
runs-on: ubuntu-latest
outputs:
release_run: ${{ steps.release_check.outputs.release_run }}
steps:
- name: Release check
id: release_check
run: |
COMMIT_MSG="$(gh api /repos/${{ github.repository}}/commits/${{ env.DEFAULT_REPO_BRANCH }} --jq '.commit.message')"
if [[ "${COMMIT_MSG}" =~ ^Release\ v.*\ -\ Changelog$ ]]; then
echo "In a release - do not run this job !"
RELEASE_RUN=true
else
echo "Not a release - update docs"
RELEASE_RUN=false
fi
echo "RELEASE_RUN=${RELEASE_RUN}" >> $GITHUB_ENV
echo "::set-output name=release_run::${RELEASE_RUN}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository
if: env.RELEASE_RUN == 'false'
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Set up Python 3.10
if: env.RELEASE_RUN == 'false'
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
if: env.RELEASE_RUN == 'false'
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install -r requirements.txt -r requirements-dev.txt -r requirements-client.txt -r requirements-http-client.txt -r requirements-docs.txt
pip install -e .[all]
- name: Set up git user
if: env.RELEASE_RUN == 'false'
run: |
git config --global user.name "${{ env.GIT_USER_NAME }}"
git config --global user.email "${{ env.GIT_USER_EMAIL }}"
- name: Check API Reference and landing page
if: env.RELEASE_RUN == 'false'
run: |
invoke create-api-reference-docs --pre-clean
if [ -n "$(git status --porcelain docs/api_reference)" ]; then
echo "The following files in the documentation have not been committed:"
git status --porcelain docs/api_reference
exit 1
fi
- name: Update changelog with unreleased changes
uses: CharMixer/auto-changelog-action@v1
with:
token: ${{ secrets.RELEASE_PAT_BOT }}
release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }}
exclude_labels: "duplicate,question,invalid,wontfix,dependency_updates,skip_changelog"
future_release: "Unreleased changes"
- name: Deploy documentation
if: env.RELEASE_RUN == 'false'
run: mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest ${{ env.DEFAULT_REPO_BRANCH }}
update-dependabot-branch:
name: Update permanent dependabot branch `dependabot_updates`
if: github.repository_owner == 'Materials-Consortia'
runs-on: ubuntu-latest
env:
DEPENDABOT_BRANCH: dependabot_updates
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.DEPENDABOT_BRANCH }}
fetch-depth: 0
- name: Set up git config
run: |
git config --global user.name "${{ env.GIT_USER_NAME }}"
git config --global user.email "${{ env.GIT_USER_EMAIL }}"
- name: Update '${{ env.DEPENDABOT_BRANCH }}'
run: |
git fetch origin
LATEST_PR_BODY="$(gh api /repos/${{ github.repository}}/pulls -X GET -f state=closed -f per_page=1 -f sort=updated -f direction=desc --jq '.[].body')"
cat .github/utils/single_dependency_pr_body.txt | head -8 > .tmp_file.txt
if [ -z "$(printf '%s\n' "${LATEST_PR_BODY}" | head -8 | diff - .tmp_file.txt --strip-trailing-cr)" ]; then
# The dependency branch has just been merged into ${DEFAULT_REPO_BRANCH}
# The dependency branch should be reset to ${DEFAULT_REPO_BRANCH}
echo "The dependencies have just been updated! Reset to ${{ env.DEFAULT_REPO_BRANCH }}."
git reset --hard origin/${{ env.DEFAULT_REPO_BRANCH }}
echo "FORCE_PUSH=yes" >> $GITHUB_ENV
else
# Normal procedure: Merge ${DEFAULT_REPO_BRANCH} into ${DEPENDABOT_BRANCH}
echo "Merge new updates to ${{ env.DEFAULT_REPO_BRANCH }} into ${DEPENDABOT_BRANCH}"
git merge -m "Keep '${{ env.DEPENDABOT_BRANCH }}' up-to-date with '${{ env.DEFAULT_REPO_BRANCH }}'" origin/${{ env.DEFAULT_REPO_BRANCH }}
echo "FORCE_PUSH=no" >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push to '${{ env.DEPENDABOT_BRANCH }}'
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.RELEASE_PAT_BOT }}
branch: ${{ env.DEPENDABOT_BRANCH }}
sleep: 15
force: ${{ env.FORCE_PUSH }}
deploy-fly:
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
OPTIMADE_CONFIG_FILE: /app/tests/test_config.json
OPTIMADE_BASE_URL: https://optimade.fly.dev
runs-on: ubuntu-latest
if: github.repository_owner == 'Materials-Consortia'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Set up Fly
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy to Fly
run: flyctl deploy --remote-only -c ./.github/fly.toml
publish_container_image:
name: Publish container image
needs: deploy_docs
uses: ./.github/workflows/cd_container_image.yml
if: needs.deploy_docs.outputs.release_run == 'false'
with:
release: false
checkout_ref: ${{ github.sha }}
secrets: inherit
permissions:
packages: write
contents: read