diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index e50c863..0000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Build and push docker image - -on: - push: - tags: [ 'v*.*.*' ] - -jobs: - push_to_registry: - environment: docker_build - runs-on: ubuntu-latest - steps: - - - name: Set env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v6 - with: - push: true - tags: | - ghcr.io/fhcrc/deenurp:latest - ghcr.io/fhcrc/deenurp:${{ env.RELEASE_VERSION }} diff --git a/.github/workflows/test-publish.yml b/.github/workflows/test-publish.yml new file mode 100644 index 0000000..b38698b --- /dev/null +++ b/.github/workflows/test-publish.yml @@ -0,0 +1,90 @@ +--- +name: Run tests and deploy to registry + +on: + push: + branches: + - "*" + tags: + - "v*.*.*" + pull_request: + branches: + - $default-branch + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + unittests: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - uses: actions/checkout@v4 + - run: | + python3 -m deenurp.test + tests/run.sh + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install package and dependencies + run: | + python -m pip install --upgrade pip wheel + python -m pip install . + + - name: Run tests + run: python -m unittest discover + + deploy: + if: github.ref_type == 'tag' + needs: [unittests] + permissions: + contents: read + packages: write + id-token: write + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push + id: build-and-push + uses: docker/build-push-action@v6 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ steps.meta.outputs.tags }} + + - name: Sign the published Docker image + env: + DIGEST: ${{ steps.build-and-push.outputs.digest }} + TAGS: ${{ steps.meta.outputs.tags }} + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 91ac9b0..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Run deenurp tests on deenurp image - -on: push - -jobs: - dev_image: - environment: docker_build - runs-on: ubuntu-latest - outputs: - sha_short: ${{ env.sha_short }} - steps: - - - name: Set env - run: echo "sha_short=`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v6 - with: - push: true - tags: ghcr.io/fhcrc/deenurp:${{ env.sha_short }} - test: - needs: [dev_image] - runs-on: ubuntu-latest - container: - image: ghcr.io/fhcrc/deenurp:${{ needs.dev_image.outputs.sha_short }} - steps: - - uses: actions/checkout@v4 - - run: | - python3 -m deenurp.test - tests/run.sh