Debian Codegraph @

.github/workflows/cd.yml

raw
1 name: Continuous Delivery
2
3 on:
4 push:
5 tags: 'v*' # push events to matching v*, i.e. v1.0, v20.15.10
6
7 env:
8 CD: "true"
9 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 PYTHON_DEFAULT_VERSION: "3.12"
11
12 jobs:
13 deploy:
14 env:
15 B2_PYPI_PASSWORD: ${{ secrets.B2_PYPI_PASSWORD }}
16 runs-on: ubuntu-latest
17 outputs:
18 version: ${{ steps.build.outputs.version }}
19 prerelease: ${{ steps.prerelease_check.outputs.prerelease }}
20 # publish_docker: ${{ steps.prerelease_check.outputs.prerelease == 'false' && secrets.DOCKERHUB_USERNAME != '' }} # doesn't work, hence the workaround
21 publish_docker: ${{ steps.prerelease_check.outputs.publish_docker }}
22 steps:
23 - name: Determine if pre-release
24 id: prerelease_check
25 run: |
26 export IS_PRERELEASE=$([[ ${{ github.ref }} =~ [^0-9]$ ]] && echo true || echo false)
27 echo "prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT
28 export PUBLISH_DOCKER=$([[ $IS_PRERELEASE == 'false' && "${{ secrets.DOCKERHUB_USERNAME }}" != '' ]] && echo true || echo false)
29 echo "publish_docker=$PUBLISH_DOCKER" >> $GITHUB_OUTPUT
30 - uses: actions/checkout@v4
31 with:
32 fetch-depth: 0
33 - name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
34 uses: actions/setup-python@v5
35 with:
36 python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
37 - name: Install dependencies
38 run: python -m pip install --upgrade nox pdm
39 - name: Build the distribution
40 id: build
41 run: nox -vs build
42 - name: Read the Changelog
43 id: read-changelog
44 uses: mindsers/changelog-reader-action@v2
45 with:
46 version: ${{ steps.build.outputs.version }}
47 - name: Create GitHub release and upload the distribution
48 id: create-release
49 uses: softprops/action-gh-release@v2
50 with:
51 name: ${{ steps.build.outputs.version }}
52 body: ${{ steps.read-changelog.outputs.changes }}
53 draft: false
54 prerelease: ${{ steps.prerelease_check.outputs.prerelease }}
55 files: ${{ steps.build.outputs.asset_path }}
56 - name: Upload the distribution to PyPI
57 if: ${{ env.B2_PYPI_PASSWORD != '' && steps.prerelease_check.outputs.prerelease == 'false' }}
58 uses: pypa/[email protected]
59 with:
60 user: __token__
61 password: ${{ secrets.B2_PYPI_PASSWORD }}
62 deploy-linux-bundle:
63 needs: deploy
64 runs-on: ubuntu-latest
65 container:
66 image: "python:3.12" # can not use ${{ env.PYTHON_DEFAULT_VERSION }} here
67 env:
68 DEBIAN_FRONTEND: noninteractive
69 steps:
70 - uses: actions/checkout@v4
71 with:
72 fetch-depth: 0
73 - name: Install dependencies
74 run: |
75 apt-get -y update
76 apt-get -y install patchelf
77 python -m pip install --upgrade nox pdm
78 git config --global --add safe.directory '*'
79 - name: Bundle the distribution
80 id: bundle
81 run: nox -vs bundle
82 - name: Sign the bundle
83 id: sign
84 run: nox -vs sign
85 - name: Generate hashes
86 id: hashes
87 run: nox -vs make_dist_digest
88 - name: Upload the bundle to the GitHub release
89 uses: softprops/action-gh-release@v2
90 with:
91 name: ${{ needs.deploy.outputs.version }}
92 draft: false
93 prerelease: ${{ needs.deploy.outputs.prerelease }}
94 files: ${{ steps.sign.outputs.asset_path }}
95 deploy-windows-bundle:
96 needs: deploy
97 env:
98 B2_WINDOWS_CODE_SIGNING_CERTIFICATE: ${{ secrets.B2_WINDOWS_CODE_SIGNING_CERTIFICATE }}
99 B2_WINDOWS_CODE_SIGNING_CERTIFICATE_PASSWORD: ${{ secrets.B2_WINDOWS_CODE_SIGNING_CERTIFICATE_PASSWORD }}
100 runs-on: windows-2019
101 steps:
102 - uses: actions/checkout@v4
103 with:
104 fetch-depth: 0
105 - name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
106 uses: actions/setup-python@v5
107 with:
108 python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
109 - name: Install dependencies
110 run: python -m pip install --upgrade nox pdm
111 - name: Bundle the distribution
112 id: bundle
113 shell: bash
114 run: nox -vs bundle
115 - name: Import certificate
116 id: windows_import_cert
117 if: ${{ env.B2_WINDOWS_CODE_SIGNING_CERTIFICATE != '' }}
118 uses: timheuer/base64-to-file@v1
119 with:
120 fileName: 'cert.pfx'
121 encodedString: ${{ secrets.B2_WINDOWS_CODE_SIGNING_CERTIFICATE }}
122 - name: Sign the bundle
123 if: ${{ env.B2_WINDOWS_CODE_SIGNING_CERTIFICATE != '' }}
124 id: sign
125 shell: bash
126 run: nox -vs sign -- '${{ steps.windows_import_cert.outputs.filePath }}' '${{ env.B2_WINDOWS_CODE_SIGNING_CERTIFICATE_PASSWORD }}'
127 - name: Generate hashes
128 id: hashes
129 run: nox -vs make_dist_digest
130 - name: Create GitHub release and upload the distribution
131 id: create-release
132 uses: softprops/action-gh-release@v2
133 with:
134 name: ${{ needs.deploy.outputs.version }}
135 draft: false
136 prerelease: ${{ needs.deploy.outputs.prerelease }}
137 files:
138 ${{ steps.sign.outputs.asset_path || steps.bundle.outputs.asset_path }}
139 deploy-docker:
140 needs: deploy
141 if: ${{ needs.deploy.outputs.publish_docker == 'true' }}
142 runs-on: ubuntu-latest
143 env:
144 DEBIAN_FRONTEND: noninteractive
145 steps:
146 - uses: actions/checkout@v4
147 with:
148 fetch-depth: 0
149 - name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
150 uses: actions/setup-python@v5
151 with:
152 python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
153 - name: Install dependencies
154 run: python -m pip install --upgrade nox pdm
155 - name: Build Dockerfile
156 run: nox -vs generate_dockerfile
157 - name: Set up QEMU
158 uses: docker/setup-qemu-action@v3
159 - name: Set up Docker Buildx
160 uses: docker/setup-buildx-action@v3
161 - name: Prepare Docker tags
162 id: docker_tags_prep
163 run: |
164 DOCKER_TAGS=backblazeit/b2:${{ needs.deploy.outputs.version }}
165 if [ "${{ needs.deploy.outputs.prerelease }}" != "true" ]; then
166 DOCKER_TAGS="$DOCKER_TAGS,backblazeit/b2:latest"
167 fi
168 echo DOCKER_TAGS=$DOCKER_TAGS
169 echo "docker_tags=$DOCKER_TAGS" >> $GITHUB_OUTPUT
170 - name: Login to Docker Hub
171 uses: docker/login-action@v3
172 with:
173 username: ${{ secrets.DOCKERHUB_USERNAME }}
174 password: ${{ secrets.DOCKERHUB_TOKEN }}
175 - name: Build and push
176 uses: docker/build-push-action@v3
177 with:
178 context: .
179 push: true
180 tags: ${{ steps.docker_tags_prep.outputs.docker_tags }}
181 platforms: linux/amd64,linux/arm64
182 - name: Update Docker Hub Description
183 uses: peter-evans/dockerhub-description@v4
184 with:
185 username: ${{ secrets.DOCKERHUB_USERNAME }}
186 password: ${{ secrets.DOCKERHUB_TOKEN }}
187 repository: backblazeit/b2
188 short-description: "Official Backblaze B2 CLI docker image"