33 push :
44 branches :
55 - main
6- - ' stable/*'
76 tags :
8- - ' *'
7+ # Only match non-prerelease tags.
8+ - ' [0-9]+.[0-9]+.[0-9]'
99 workflow_dispatch :
1010 inputs :
1111 deploy_prefix :
@@ -27,12 +27,23 @@ jobs:
2727 name : Build
2828 runs-on : ubuntu-latest
2929
30+ outputs :
31+ latest_tag : ${{ steps.latest_tag.outputs.latest_tag }}
32+
3033 steps :
3134 - uses : actions/checkout@v3
3235 with :
33- # We need to fetch the whole history so 'reno' can do its job.
36+ # We need to fetch the whole history so 'reno' can do its job and we can inspect tags .
3437 fetch-depth : 0
3538
39+ - name : Determine latest full release tag
40+ id : latest_tag
41+ run : |
42+ set -e
43+ latest_tag=$(git tag --list --sort=-version:refname | sed -n '/^[0-9]\+\.[0-9]\+\.[0-9]\+$/p' | head -n 1)
44+ echo "Latest release tag: '$latest_tag'"
45+ echo "latest_tag=$latest_tag" >> "$GITHUB_OUTPUT"
46+
3647 - uses : actions/setup-python@v4
3748 name : Install Python
3849 with :
@@ -107,42 +118,61 @@ jobs:
107118 path : deploy
108119
109120 - id : choose
110- name : Choose deployment location
121+ name : Choose deployment location(s)
111122 run : |
112123 set -e
124+ declare -a prefixes
113125 case ${{ github.event_name }} in
114126 push)
115- case ${{ github.ref_name }} in
116- main)
117- echo "deploy_prefix=dev" >> "$GITHUB_OUTPUT"
127+ case ${{ github.ref_type }} in
128+ branch)
129+ if [[ "$GITHUB_REF_NAME" != "main" ]]; then
130+ echo "Push to unhandled branch '$GITHUB_REF_NAME'" >&2
131+ exit 1
132+ fi
133+
134+ prefixes+=( "dev" )
118135 ;;
119- # This currently deploys to the documentation root on a push to _any_ stable branch;
120- # when we're supporting more than one version at once, it will need revisiting.
121- stable/*)
122- echo "deploy_prefix=" >> "$GITHUB_OUTPUT"
136+ tag)
137+ tag=$GITHUB_REF_NAME
138+ echo "Full tag: ${tag}"
139+ IFS=. read -ra version <<< "$tag"
140+ minor_version="${version[0]}.${version[1]}"
141+ echo "Minor version: ${minor_version}"
142+ prefixes+=( "stable/${minor_version}" )
143+ if [[ "$tag" == "$LATEST_TAG" ]]; then
144+ # Deploy to the root as well.
145+ prefixes+=( "" )
146+ fi
123147 ;;
124148 *)
125- echo "Push to unhandled branch ${{ github.ref_name }}" >&2
149+ echo "Unhandled reference type ' ${{ github.ref_type }}' " >&2
126150 exit 1
127151 ;;
128152 esac
129153 ;;
130- tag)
131- tag=${{ github.ref_name }}
132- echo "Full tag: ${tag}"
133- IFS=. read -ra version <<< "$tag"
134- minor_version="${version[0]}.${version[1]}"
135- echo "Minor version: ${minor_version}"
136- echo "deploy_prefix=stable/${minor_version}" >> "$GITHUB_OUTPUT"
137- ;;
138154 workflow_dispatch)
139- echo "deploy_prefix=${{ inputs.deploy_prefix }}" >> "$GITHUB_OUTPUT"
155+ prefixes+=( "$WORKFLOW_DISPATCH_PREFIX" )
140156 ;;
141157 *)
142158 echo "Unhandled GitHub event ${{ github.event_name }}" >&2
143159 exit 1
144160 ;;
145161 esac
162+ # Join the array of prefixes into a colon-delimited list for
163+ # serialisation. This includes a trailing colon, so we can detect
164+ # the presence of the empty string, even if it's the only prefix.
165+ if [[ "${#prefixes[@]}" -gt 0 ]]; then
166+ joined_prefixes=$(printf "%s:" "${prefixes[@]}")
167+ echo "Chosen deployment prefixes: '$joined_prefixes'"
168+ echo "joined_prefixes=$joined_prefixes" >> "$GITHUB_OUTPUT"
169+ else
170+ echo "Nothing to deploy to."
171+ fi
172+ env :
173+ LATEST_TAG : ${{ needs.build.outputs.latest_tag }}
174+ GITHUB_REF_NAME : ${{ github.ref_name }}
175+ WORKFLOW_DISPATCH_PREFIX : ${{ inputs.deploy_prefix }}
146176
147177 - name : Install rclone
148178 run : |
@@ -151,17 +181,29 @@ jobs:
151181 sudo apt-get install -y ./rclone.deb
152182
153183 - name : Deploy to qiskit.org
184+ if : ${{ steps.choose.outputs.joined_prefixes != '' }}
154185 run : |
155186 set -e
156187 RCLONE_CONFIG=$(rclone config file | tail -1)
157188 openssl aes-256-cbc -K "$RCLONE_KEY" -iv "$RCLONE_IV" -in qiskit/tools/rclone.conf.enc -out "$RCLONE_CONFIG" -d
158- rclone sync --progress --exclude-from qiskit/tools/docs_exclude.txt deploy "IBMCOS:qiskit-org-web-resources/documentation/${{ steps.choose.outputs.deploy_prefix }}"
189+ IFS=: read -ra prefixes <<< "$JOINED_PREFIXES"
190+ for prefix in "${prefixes[@]}"; do
191+ # The 'documentation' bit of the prefix is hard-coded in this step
192+ # rather than being chosen during the prefix-choosing portion
193+ # because we don't want to allow the 'workflow_dispatch' event
194+ # trigger to accidentally allow a deployment to a dodgy prefix that
195+ # wipes out _everything_ on qiskit.org.
196+ location=documentation/$prefix
197+ echo "Deploying to 'qiskit.org/$location'"
198+ rclone sync --progress --exclude-from qiskit/tools/docs_exclude.txt deploy "IBMCOS:qiskit-org-web-resources/$location"
199+ done
159200 env :
160- RCLONE_KEY : ${{ secrets.encrypted_rclone_key }}
161- RCLONE_IV : ${{ secrets.encrypted_rclone_iv }}
201+ JOINED_PREFIXES : ${{ steps.choose.outputs.joined_prefixes }}
202+ RCLONE_KEY : ${{ secrets.ENCRYPTED_RCLONE_KEY}}
203+ RCLONE_IV : ${{ secrets.ENCRYPTED_RCLONE_IV }}
162204
163205 deploy_translatables :
164- if : (github.event_name == 'workflow_dispatch' && inputs.do_translatables) || (github.event_name == 'push' && startsWith( github.ref_name.startsWith, 'stable/') )
206+ if : (github.event_name == 'workflow_dispatch' && inputs.do_translatables) || (github.event_name == 'push' && github.ref_type == 'tag' && github.ref_name == needs.build.outputs.latest_tag )
165207 name : Push translatable strings
166208 needs : [build]
167209 runs-on : ubuntu-latest
@@ -184,8 +226,8 @@ jobs:
184226 echo "::add-mask::${ssh_key}"
185227 echo "ssh_key=${ssh_key}" >> "$GITHUB_OUTPUT"
186228 env :
187- SSH_UPDATE_KEY : ${{ secrets.encrypted_ssh_translatables_key }}
188- SSH_UPDATE_IV : ${{ secrets.encrypted_ssh_translatables_iv }}
229+ SSH_UPDATE_KEY : ${{ secrets.ENCRYPTED_DEPLOY_PO_BRANCH_KEY }}
230+ SSH_UPDATE_IV : ${{ secrets.ENCRYPTED_DEPLOY_PO_BRANCH_IV }}
189231
190232 - uses : actions/checkout@v3
191233 with :
0 commit comments