Skip to content

Commit 3b8681f

Browse files
JeromeBugithub-actions[bot]
authored andcommitted
ci: ci for deployement of SILL and add workflow to update the project from upstream every day
1 parent e64837b commit 3b8681f

File tree

2 files changed

+121
-69
lines changed

2 files changed

+121
-69
lines changed

.github/workflows/ci.yaml

Lines changed: 86 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -40,89 +40,106 @@ jobs:
4040
runs-on: ubuntu-latest
4141
needs: validations
4242
outputs:
43-
from_version: ${{ steps.step1.outputs.from_version }}
44-
to_version: ${{ steps.step1.outputs.to_version }}
45-
is_upgraded_version: ${{ steps.step1.outputs.is_upgraded_version }}
43+
is_upgraded_in_preprod: ${{ steps.check_version.outputs.is_upgraded_in_preprod }}
44+
is_upgraded_version: ${{ steps.check_version.outputs.is_upgraded_version }}
45+
to_version: ${{ steps.check_version.outputs.to_version }}
46+
from_version: ${{ steps.check_version.outputs.from_version }}
4647
steps:
47-
- uses: garronej/[email protected]
48-
id: step1
49-
with:
50-
action_name: is_package_json_version_upgraded
48+
- uses: actions/checkout@v4
49+
- name: Check version upgrade
50+
id: check_version
51+
run: |
52+
# Get current version from package.json
53+
CURRENT_VERSION=$(jq -r '.version' package.json)
54+
echo "Version in package.json: $CURRENT_VERSION"
5155
52-
create_tag:
53-
name: Create version tag
56+
# Get deployed version from preprod API
57+
PRE_PROD_DEPLOYED_VERSION=$(curl -s "https://code.gouv.fr/sill-preprod/api/getApiVersion" | jq -r '.result.data.json')
58+
PROD_DEPLOYED_VERSION=$(curl -s "https://code.gouv.fr/sill/api/getApiVersion" | jq -r '.result.data.json')
59+
echo "Deployed version in preprod: $PRE_PROD_DEPLOYED_VERSION"
60+
echo "Deployed version in prod: $PROD_DEPLOYED_VERSION"
61+
62+
# Simple comparison: check if versions are different
63+
if [ "$CURRENT_VERSION" != "$PRE_PROD_DEPLOYED_VERSION" ]; then
64+
IS_UPGRADED_IN_PRE_PROD="true"
65+
IS_UPGRADED="true"
66+
echo "✅ Version different from preprod ($PRE_PROD_DEPLOYED_VERSION), should deploy: $CURRENT_VERSION"
67+
elif [ "$CURRENT_VERSION" != "$PROD_DEPLOYED_VERSION" ]; then
68+
IS_UPGRADED="true"
69+
echo "✅ Version different from prod ($PROD_DEPLOYED_VERSION), should deploy: $CURRENT_VERSION"
70+
else
71+
IS_UPGRADED="false"
72+
echo "ℹ️ Version unchanged: $CURRENT_VERSION"
73+
fi
74+
75+
echo "Is version upgraded: $IS_UPGRADED"
76+
77+
# Set outputs
78+
echo "is_upgraded_version=$IS_UPGRADED" >> $GITHUB_OUTPUT
79+
echo "is_upgraded_in_preprod=$IS_UPGRADED_IN_PRE_PROD" >> $GITHUB_OUTPUT
80+
echo "to_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
81+
echo "from_version=$PRE_PROD_DEPLOYED_VERSION" >> $GITHUB_OUTPUT
82+
83+
trigger_pre_production_deploy:
84+
name: "Trigger pre-production deploy"
5485
runs-on: ubuntu-latest
86+
concurrency:
87+
group: deploy-to-pre-production
88+
cancel-in-progress: true
5589
needs:
5690
- check_if_version_upgraded
57-
if: needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true'
91+
if: needs.check_if_version_upgraded.outputs.is_upgraded_in_preprod == 'true'
5892
env:
5993
TO_VERSION: ${{ needs.check_if_version_upgraded.outputs.to_version }}
6094
steps:
61-
- name: Checkout repository
62-
uses: actions/checkout@v4
63-
- name: Create tag
95+
- run: echo "Triggering production deploy"
96+
- name: Set up SSH
6497
run: |
65-
git config --local user.email "[email protected]"
66-
git config --local user.name "GitHub Actions"
67-
git tag -a v${{ env.TO_VERSION }} -m "Deployment tag for v${{ env.TO_VERSION }}"
68-
git push --tags
98+
mkdir -p ~/.ssh
99+
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
100+
chmod 600 ~/.ssh/id_ed25519
101+
ssh-keyscan code.gouv.fr >> ~/.ssh/known_hosts
102+
103+
# Debug: Check key format
104+
echo "SSH key first line:"
105+
head -1 ~/.ssh/id_ed25519
106+
echo "SSH key last line:"
107+
tail -1 ~/.ssh/id_ed25519
108+
echo "SSH key line count:"
109+
wc -l ~/.ssh/id_ed25519
110+
111+
# Test SSH connection
112+
echo "Testing SSH connection..."
113+
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 [email protected] "echo 'SSH connection successful'"
114+
115+
# Run the actual command
116+
ssh -o StrictHostKeyChecking=no [email protected] "bash -c 'eval \"\$(ssh-agent -s)\" && ssh-add ~/.ssh/sill-data && ./update-sill-preprod.sh v${{ env.TO_VERSION }}'"
117+
env:
118+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
69119

70-
create_github_release:
71-
name: "Create release notes"
72-
runs-on: ubuntu-latest
73-
needs:
74-
- check_if_version_upgraded
75-
- create_tag
76-
if: |
77-
needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' && github.event_name == 'push'
78-
env:
79-
RELEASE_TAG: v${{ needs.check_if_version_upgraded.outputs.to_version }}
80-
steps:
81-
- name: "Generate release on github"
82-
uses: softprops/action-gh-release@v2
83-
with:
84-
name: Release ${{ env.RELEASE_TAG }}
85-
prerelease: false
86-
tag_name: ${{ env.RELEASE_TAG }}
87-
generate_release_notes: true
88-
token: ${{ secrets.GITHUB_TOKEN }}
89120

90-
docker:
91-
name: Build and push Docker images
121+
trigger_production_deploy:
122+
name: "Trigger production deploy"
92123
runs-on: ubuntu-latest
124+
environment: production
125+
concurrency:
126+
group: deploy-to-production
127+
cancel-in-progress: true
93128
needs:
129+
- trigger_pre_production_deploy
94130
- check_if_version_upgraded
131+
if: always() && needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' && (needs.trigger_pre_production_deploy.result == 'success' || needs.trigger_pre_production_deploy.result == 'skipped')
132+
env:
133+
TO_VERSION: ${{ needs.check_if_version_upgraded.outputs.to_version }}
95134
steps:
96-
- uses: actions/checkout@v4
97-
- uses: docker/setup-qemu-action@v3
98-
- uses: docker/setup-buildx-action@v3
99-
- uses: docker/login-action@v3
100-
with:
101-
username: ${{ secrets.DOCKERHUB_USERNAME }}
102-
password: ${{ secrets.DOCKERHUB_TOKEN }}
103-
- name: Computing Docker image tags
104-
id: step1
105-
env:
106-
TO_VERSION: ${{ needs.check_if_version_upgraded.outputs.to_version }}
135+
- run: echo "Triggering production deploy"
136+
- name: Set up SSH
107137
run: |
108-
OUT_API=$GITHUB_REPOSITORY-api:$TO_VERSION,$GITHUB_REPOSITORY-api:latest
109-
OUT_API=$(echo "$OUT_API" | awk '{print tolower($0)}')
110-
echo ::set-output name=docker_api_tags::$OUT_API
111-
112-
OUT_WEB=$GITHUB_REPOSITORY-web:$TO_VERSION,$GITHUB_REPOSITORY-web:latest
113-
OUT_WEB=$(echo "$OUT_WEB" | awk '{print tolower($0)}')
114-
echo ::set-output name=docker_web_tags::$OUT_WEB
115-
116-
- uses: docker/build-push-action@v5
117-
with:
118-
push: true
119-
context: .
120-
file: ./Dockerfile.api
121-
tags: ${{ steps.step1.outputs.docker_api_tags }}
122-
- uses: docker/build-push-action@v5
123-
with:
124-
push: true
125-
context: .
126-
file: ./Dockerfile.web
127-
tags: ${{ steps.step1.outputs.docker_web_tags }}
138+
mkdir -p ~/.ssh
139+
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
140+
chmod 600 ~/.ssh/id_ed25519
141+
ssh-keyscan code.gouv.fr >> ~/.ssh/known_hosts
142+
ssh -o StrictHostKeyChecking=no [email protected] "bash -c 'eval \"\$(ssh-agent -s)\" && ssh-add ~/.ssh/sill-data && ./update-sill-docker-compose.sh v${{ env.TO_VERSION }}'"
143+
env:
144+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
128145

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Sync upstream
2+
3+
on:
4+
schedule:
5+
- cron: '0 7 * * *' # every day at 7 AM UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
sync:
10+
name: Sync repository with upstream repository
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout fork
14+
uses: actions/checkout@v4
15+
with:
16+
token: ${{ secrets.PAT_FOR_UPSTREAM_SYNC }}
17+
fetch-depth: 0
18+
19+
- name: Configure Git
20+
run: |
21+
git config user.name "github-actions[bot]"
22+
git config user.email "github-actions[bot]@users.noreply.github.com"
23+
24+
- name: Add upstream remote
25+
run: |
26+
git remote add upstream https://github.com/codegouvfr/sill.git
27+
git fetch upstream
28+
29+
- name: Sync with upstream/main
30+
run: |
31+
git checkout main
32+
git rebase upstream/main
33+
34+
- name: Push to origin
35+
run: git push origin main --force-with-lease --no-verify

0 commit comments

Comments
 (0)