@@ -40,89 +40,106 @@ jobs:
40
40
runs-on : ubuntu-latest
41
41
needs : validations
42
42
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 }}
46
47
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"
51
55
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"
54
85
runs-on : ubuntu-latest
86
+ concurrency :
87
+ group : deploy-to-pre-production
88
+ cancel-in-progress : true
55
89
needs :
56
90
- 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'
58
92
env :
59
93
TO_VERSION : ${{ needs.check_if_version_upgraded.outputs.to_version }}
60
94
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
64
97
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 }}
69
119
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 }}
89
120
90
- docker :
91
- name : Build and push Docker images
121
+ trigger_production_deploy :
122
+ name : " Trigger production deploy "
92
123
runs-on : ubuntu-latest
124
+ environment : production
125
+ concurrency :
126
+ group : deploy-to-production
127
+ cancel-in-progress : true
93
128
needs :
129
+ - trigger_pre_production_deploy
94
130
- 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 }}
95
134
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
107
137
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 }}
128
145
0 commit comments