@@ -40,10 +40,12 @@ 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 :
48
+ <<<<<<< HEAD
47
49
-
uses :
garronej/[email protected]
48
50
id : step1
49
51
with :
@@ -52,82 +54,89 @@ jobs:
52
54
echo "from_version=${{ steps.step1.outputs.from_version }}"
53
55
echo "to_version=${{ steps.step1.outputs.to_version }}"
54
56
echo "is_upgraded_version=${{ steps.step1.outputs.is_upgraded_version }}"
57
+ =======
58
+ - uses : actions/checkout@v4
59
+ - name : Check version upgrade
60
+ id : check_version
61
+ run : |
62
+ # Get current version from package.json
63
+ CURRENT_VERSION=$(jq -r '.version' package.json)
64
+ echo "Version in package.json: $CURRENT_VERSION"
65
+ >>>>>>> 3b8681fc (ci: ci for deployement of SILL and add workflow to update the project from upstream every day)
66
+
67
+ # Get deployed version from preprod API
68
+ PRE_PROD_DEPLOYED_VERSION=$(curl -s "https://code.gouv.fr/sill-preprod/api/getApiVersion" | jq -r '.result.data.json')
69
+ PROD_DEPLOYED_VERSION=$(curl -s "https://code.gouv.fr/sill/api/getApiVersion" | jq -r '.result.data.json')
70
+ echo "Deployed version in preprod : $PRE_PROD_DEPLOYED_VERSION"
71
+ echo "Deployed version in prod : $PROD_DEPLOYED_VERSION"
72
+
73
+ # Simple comparison: check if versions are different
74
+ if [ "$CURRENT_VERSION" != "$PRE_PROD_DEPLOYED_VERSION" ]; then
75
+ IS_UPGRADED_IN_PRE_PROD="true"
76
+ IS_UPGRADED="true"
77
+ echo "✅ Version different from preprod ($PRE_PROD_DEPLOYED_VERSION), should deploy : $CURRENT_VERSION"
78
+ elif [ "$CURRENT_VERSION" != "$PROD_DEPLOYED_VERSION" ]; then
79
+ IS_UPGRADED="true"
80
+ echo "✅ Version different from prod ($PROD_DEPLOYED_VERSION), should deploy : $CURRENT_VERSION"
81
+ else
82
+ IS_UPGRADED="false"
83
+ echo "ℹ️ Version unchanged : $CURRENT_VERSION"
84
+ fi
85
+
86
+ echo "Is version upgraded : $IS_UPGRADED"
87
+
88
+ # Set outputs
89
+ echo "is_upgraded_version=$IS_UPGRADED" >> $GITHUB_OUTPUT
90
+ echo "is_upgraded_in_preprod=$IS_UPGRADED_IN_PRE_PROD" >> $GITHUB_OUTPUT
91
+ echo "to_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
92
+ echo "from_version=$PRE_PROD_DEPLOYED_VERSION" >> $GITHUB_OUTPUT
55
93
56
- create_tag :
57
- name : Create version tag
94
+ trigger_pre_production_deploy :
95
+ name : " Trigger pre-production deploy "
58
96
runs-on : ubuntu-latest
97
+ concurrency :
98
+ group : deploy-to-pre-production
99
+ cancel-in-progress : true
59
100
needs :
60
101
- check_if_version_upgraded
61
- if : needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true'
102
+ if : needs.check_if_version_upgraded.outputs.is_upgraded_in_preprod == 'true'
62
103
env :
63
104
TO_VERSION : ${{ needs.check_if_version_upgraded.outputs.to_version }}
64
105
steps :
65
- - name : Checkout repository
66
- uses : actions/checkout@v4
67
- - name : Create tag
106
+ - run : echo "Triggering production deploy"
107
+ - name : Set up SSH
68
108
run : |
69
- git config --local user.email "[email protected] "
70
- git config --local user.name "GitHub Actions"
71
- git tag -a v${{ env.TO_VERSION }} -m "Deployment tag for v${{ env.TO_VERSION }}"
72
- git push --tags
109
+ mkdir -p ~/.ssh
110
+ echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
111
+ chmod 600 ~/.ssh/id_ed25519
112
+ ssh-keyscan code.gouv.fr >> ~/.ssh/known_hosts
113
+ 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 }}'"
114
+ env :
115
+ SSH_PRIVATE_KEY : ${{ secrets.SSH_PRIVATE_KEY }}
73
116
74
- create_github_release :
75
- name : " Create release notes"
76
- runs-on : ubuntu-latest
77
- needs :
78
- - check_if_version_upgraded
79
- - create_tag
80
- if : |
81
- needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' && github.event_name == 'push'
82
- env :
83
- RELEASE_TAG : v${{ needs.check_if_version_upgraded.outputs.to_version }}
84
- steps :
85
- - name : " Generate release on github"
86
- uses : softprops/action-gh-release@v2
87
- with :
88
- name : Release ${{ env.RELEASE_TAG }}
89
- prerelease : false
90
- tag_name : ${{ env.RELEASE_TAG }}
91
- generate_release_notes : true
92
- token : ${{ secrets.GITHUB_TOKEN }}
93
117
94
- docker :
95
- name : Build and push Docker images
118
+ trigger_production_deploy :
119
+ name : " Trigger production deploy "
96
120
runs-on : ubuntu-latest
121
+ environment : production
122
+ concurrency :
123
+ group : deploy-to-production
124
+ cancel-in-progress : true
97
125
needs :
126
+ - trigger_pre_production_deploy
98
127
- check_if_version_upgraded
99
- if : needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true'
128
+ 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')
129
+ env :
130
+ TO_VERSION : ${{ needs.check_if_version_upgraded.outputs.to_version }}
100
131
steps :
101
- - uses : actions/checkout@v4
102
- - uses : docker/setup-qemu-action@v3
103
- - uses : docker/setup-buildx-action@v3
104
- - uses : docker/login-action@v3
105
- with :
106
- username : ${{ secrets.DOCKERHUB_USERNAME }}
107
- password : ${{ secrets.DOCKERHUB_TOKEN }}
108
- - name : Computing Docker image tags
109
- id : step1
110
- env :
111
- TO_VERSION : ${{ needs.check_if_version_upgraded.outputs.to_version }}
132
+ - run : echo "Triggering production deploy"
133
+ - name : Set up SSH
112
134
run : |
113
- OUT_API=$GITHUB_REPOSITORY-api:$TO_VERSION,$GITHUB_REPOSITORY-api:latest
114
- OUT_API=$(echo "$OUT_API" | awk '{print tolower($0)}')
115
- echo ::set-output name=docker_api_tags::$OUT_API
116
-
117
- OUT_WEB=$GITHUB_REPOSITORY-web:$TO_VERSION,$GITHUB_REPOSITORY-web:latest
118
- OUT_WEB=$(echo "$OUT_WEB" | awk '{print tolower($0)}')
119
- echo ::set-output name=docker_web_tags::$OUT_WEB
120
-
121
- - uses : docker/build-push-action@v5
122
- with :
123
- push : true
124
- context : .
125
- file : ./Dockerfile.api
126
- tags : ${{ steps.step1.outputs.docker_api_tags }}
127
- - uses : docker/build-push-action@v5
128
- with :
129
- push : true
130
- context : .
131
- file : ./Dockerfile.web
132
- tags : ${{ steps.step1.outputs.docker_web_tags }}
135
+ mkdir -p ~/.ssh
136
+ echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
137
+ chmod 600 ~/.ssh/id_ed25519
138
+ ssh-keyscan code.gouv.fr >> ~/.ssh/known_hosts
139
+ 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 }}'"
140
+ env :
141
+ SSH_PRIVATE_KEY : ${{ secrets.SSH_PRIVATE_KEY }}
133
142
0 commit comments