|
| 1 | +name: ci/cd |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + repository_dispatch: |
| 5 | + types: [build] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + strategy: |
| 11 | + fail-fast: false |
| 12 | + matrix: |
| 13 | + platform: |
| 14 | + - linux/amd64 |
| 15 | + - linux/arm64 |
| 16 | + runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-24.04' || matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' }} |
| 17 | + name: build ${{ matrix.platform }} |
| 18 | + outputs: |
| 19 | + tag: ${{ steps.envvars.outputs.tag }} |
| 20 | + steps: |
| 21 | + - name: checkout |
| 22 | + uses: actions/checkout@v5.0.0 |
| 23 | + |
| 24 | + - name: Prepare env |
| 25 | + id: envvars |
| 26 | + run: | |
| 27 | + platform=${{ matrix.platform }} |
| 28 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 29 | + if [ ${{ github.event.client_payload.tag }} != 'null' ]; then |
| 30 | + echo "tag=${{ github.event.client_payload.tag }}" >> $GITHUB_OUTPUT |
| 31 | + else |
| 32 | + echo "tag=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT |
| 33 | + fi |
| 34 | +
|
| 35 | + - name: Metadata |
| 36 | + id: meta |
| 37 | + uses: docker/metadata-action@v5.8.0 |
| 38 | + with: |
| 39 | + images: ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }} |
| 40 | + |
| 41 | + - name: Authenticate with GHCR |
| 42 | + id: auth |
| 43 | + uses: docker/login-action@v3.5.0 |
| 44 | + with: |
| 45 | + registry: ghcr.io |
| 46 | + username: ${{github.actor}} |
| 47 | + password: ${{secrets.BUILD_TOKEN}} |
| 48 | + |
| 49 | + - name: Set up Docker Buildx |
| 50 | + id: buildx |
| 51 | + uses: docker/setup-buildx-action@v3.11.1 |
| 52 | + |
| 53 | + - name: Build and push by digest |
| 54 | + id: build |
| 55 | + uses: docker/build-push-action@v6.18.0 |
| 56 | + with: |
| 57 | + file: ./docker/Dockerfile |
| 58 | + platforms: ${{ matrix.platform }} |
| 59 | + labels: ${{ steps.meta.outputs.labels }} |
| 60 | + tags: ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }} |
| 61 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 62 | + |
| 63 | + - name: Export digest |
| 64 | + run: | |
| 65 | + mkdir -p ${{ runner.temp }}/digests |
| 66 | + digest="${{ steps.build.outputs.digest }}" |
| 67 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 68 | +
|
| 69 | + - name: Upload digest |
| 70 | + uses: actions/upload-artifact@v4.6.2 |
| 71 | + with: |
| 72 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 73 | + path: ${{ runner.temp }}/digests/* |
| 74 | + if-no-files-found: error |
| 75 | + retention-days: 1 |
| 76 | + |
| 77 | + merge: |
| 78 | + runs-on: ubuntu-24.04 |
| 79 | + name: merge into multiarch manifest |
| 80 | + needs: |
| 81 | + - build |
| 82 | + steps: |
| 83 | + - name: Download digests |
| 84 | + uses: actions/download-artifact@v5.0.0 |
| 85 | + with: |
| 86 | + path: ${{ runner.temp }}/digests |
| 87 | + pattern: digests-* |
| 88 | + merge-multiple: true |
| 89 | + |
| 90 | + - name: Authenticate with GHCR |
| 91 | + id: auth |
| 92 | + uses: docker/login-action@v3.5.0 |
| 93 | + with: |
| 94 | + registry: ghcr.io |
| 95 | + username: ${{github.actor}} |
| 96 | + password: ${{secrets.BUILD_TOKEN}} |
| 97 | + |
| 98 | + - name: Set up Docker Buildx |
| 99 | + id: buildx |
| 100 | + uses: docker/setup-buildx-action@v3.11.1 |
| 101 | + |
| 102 | + - name: Metadata |
| 103 | + id: meta |
| 104 | + uses: docker/metadata-action@v5.8.0 |
| 105 | + with: |
| 106 | + images: ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }} |
| 107 | + tags: dev |
| 108 | + |
| 109 | + - name: Create manifest list and push |
| 110 | + id: annotate |
| 111 | + continue-on-error: true |
| 112 | + working-directory: ${{ runner.temp }}/digests |
| 113 | + run: | |
| 114 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 115 | + --annotation='index:org.opencontainers.image.description=${{ github.event.repository.description }}' \ |
| 116 | + --annotation='index:org.opencontainers.image.licenses=MIT' \ |
| 117 | + --annotation='index:org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }}' \ |
| 118 | + --annotation='index:org.opencontainers.image.url=${{ github.event.repository.url }}' \ |
| 119 | + --annotation='index:org.opencontainers.image.source=${{ github.event.repository.url }}' \ |
| 120 | + $(printf 'ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}@sha256:%s ' *) |
| 121 | +
|
| 122 | + - name: Create manifest list and push without annotations |
| 123 | + if: steps.annotate.outcome == 'failure' |
| 124 | + working-directory: ${{ runner.temp }}/digests |
| 125 | + run: | |
| 126 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 127 | + $(printf 'ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}@sha256:%s ' *) |
| 128 | +
|
| 129 | + - name: Inspect image |
| 130 | + run: | |
| 131 | + docker buildx imagetools inspect ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}:dev |
| 132 | +
|
| 133 | + tests: |
| 134 | + strategy: |
| 135 | + fail-fast: false |
| 136 | + matrix: |
| 137 | + platform: |
| 138 | + - linux/amd64 |
| 139 | + #- linux/arm64 |
| 140 | + runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-latest' || matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' }} |
| 141 | + name: testing on ${{ matrix.platform }} |
| 142 | + timeout-minutes: 360 |
| 143 | + needs: |
| 144 | + - build |
| 145 | + - merge |
| 146 | + steps: |
| 147 | + |
| 148 | + - name: Test notebooks |
| 149 | + shell: bash |
| 150 | + run: | |
| 151 | + docker run -t ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}:dev bash -c " \ |
| 152 | + mkdir us5; \ |
| 153 | + cd us5; \ |
| 154 | + ln -s ../data/md5.rst md.rst; \ |
| 155 | + bash ../scripts/setup_umb_samp.sh; \ |
| 156 | + bash run_umb_samp.sh; \ |
| 157 | + wait; \ |
| 158 | + bash ../scripts/run_wham.sh; \ |
| 159 | + wait; \ |
| 160 | + cpptraj < ../data/make_us_trj.in &> make_us_trj.log; \ |
| 161 | + wait; \ |
| 162 | + cd ..; \ |
| 163 | + mkdir adiab5; \ |
| 164 | + cd adiab5; \ |
| 165 | + ln -s ../us5/rc-0.30/md1ps.rst md1ps_rc-0.3.rst; \ |
| 166 | + bash ../scripts/run_adiab_all.sh; \ |
| 167 | + wait; \ |
| 168 | + cpptraj < ../data/make_adiab_trj.in &> make_adiab_trj.log; \ |
| 169 | + wait; \ |
| 170 | + cd ..; \ |
| 171 | + pip install pytest nbmake; \ |
| 172 | + find . -name '*.ipynb' | pytest --nbmake --nbmake-timeout=3600; " |
| 173 | +
|
| 174 | + tags: |
| 175 | + runs-on: ubuntu-24.04 |
| 176 | + if: github.event_name != 'pull_request' |
| 177 | + name: add tags |
| 178 | + needs: |
| 179 | + - build |
| 180 | + - tests |
| 181 | + steps: |
| 182 | + - name: Authenticate with GHCR |
| 183 | + id: auth |
| 184 | + uses: docker/login-action@v3.5.0 |
| 185 | + with: |
| 186 | + registry: "ghcr.io" |
| 187 | + username: ${{github.actor}} |
| 188 | + password: ${{secrets.BUILD_TOKEN}} |
| 189 | + |
| 190 | + - name: tag release versions |
| 191 | + shell: bash |
| 192 | + run: | |
| 193 | + docker buildx imagetools create \ |
| 194 | + --tag ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}:latest \ |
| 195 | + --tag ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}:${{ needs.build.outputs.tag }} \ |
| 196 | + ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}:dev |
| 197 | +
|
| 198 | + - name: Post version update to dash |
| 199 | + uses: peter-evans/repository-dispatch@v3.0.0 |
| 200 | + with: |
| 201 | + token: ${{ secrets.BUILD_TOKEN }} |
| 202 | + repository: jimboid/biosim-workshops-dash |
| 203 | + event-type: build |
| 204 | + client-payload: '{"repo": "${{ github.event.repository.name }}", "tag": "${{ needs.build.outputs.tag }}"}' |
0 commit comments