diff --git a/.github/workflows/tag_and_publish.yml b/.github/workflows/publish_dev.yml similarity index 67% rename from .github/workflows/tag_and_publish.yml rename to .github/workflows/publish_dev.yml index c71355d..bed4e37 100644 --- a/.github/workflows/tag_and_publish.yml +++ b/.github/workflows/publish_dev.yml @@ -1,20 +1,19 @@ -name: Tag and publish +name: Publish dev on: push: branches: - - main + - dev + jobs: - tag: - uses: AllenNeuralDynamics/aind-github-actions/.github/workflows/tag.yml@main - secrets: - SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }} publish: runs-on: ubuntu-latest - needs: tag steps: - uses: actions/checkout@v3 - - name: Pull latest changes - run: git pull origin main + - name: Compute new docker image tag + run: | + echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV" + echo "branch=$(echo ${GITHUB_REF_NAME})" >> "$GITHUB_ENV" + echo "docker_tag=$(echo ${GITHUB_REF_NAME})-$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV" - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v2 @@ -31,5 +30,5 @@ jobs: context: . push: true tags: | - ghcr.io/allenneuraldynamics/aind-data-transfer-service:${{ needs.tag.outputs.new_version }} - ghcr.io/allenneuraldynamics/aind-data-transfer-service:latest + ghcr.io/allenneuraldynamics/aind-data-transfer-service:${{ env.docker_tag }} + ghcr.io/allenneuraldynamics/aind-data-transfer-service:dev diff --git a/.github/workflows/publish_main.yml b/.github/workflows/publish_main.yml new file mode 100644 index 0000000..a12722e --- /dev/null +++ b/.github/workflows/publish_main.yml @@ -0,0 +1,43 @@ +name: Tag and publish main +on: + push: + branches: + - main + +jobs: + tag_and_publish: + name: Parse version + runs-on: ubuntu-latest + outputs: + pkg_version: ${{ steps.output_version.outputs.pkg_version }} + steps: + - uses: actions/checkout@v3 + - name: Get version from file + run: | + pkg_name=$(grep -P 'version = \{attr = .*\}' pyproject.toml | grep -oP '\w+.__version__') + init_file="./src/${pkg_name//.__version__}/__init__.py" + pkg_version=$(grep -Po '[0-9]+\.[0-9]+\.[0-9]+' "$init_file") + echo "docker_tag=$pkg_version" >> "$GITHUB_ENV" + - name: Create git tag + run: | + git tag "v${{ env.docker_tag }}" + - name: Push git tag + run: git push origin "v${{ env.docker_tag }}" + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Github Packages + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build image and push to GitHub Container Registry + uses: docker/build-push-action@v3 + with: + # relative path to the place where source code with Dockerfile is located + context: . + push: true + tags: | + ghcr.io/allenneuraldynamics/aind-data-transfer-service:${{ env.docker_tag }} + ghcr.io/allenneuraldynamics/aind-data-transfer-service:latest diff --git a/.github/workflows/test_and_lint.yml b/.github/workflows/run_dev_tests.yml similarity index 94% rename from .github/workflows/test_and_lint.yml rename to .github/workflows/run_dev_tests.yml index 51a8319..b91f152 100644 --- a/.github/workflows/test_and_lint.yml +++ b/.github/workflows/run_dev_tests.yml @@ -1,9 +1,9 @@ -name: Lint and run tests +name: Run checks in dev on: pull_request: branches: - - main + - dev jobs: ci: diff --git a/.github/workflows/run_main_tests.yml b/.github/workflows/run_main_tests.yml new file mode 100644 index 0000000..0e32080 --- /dev/null +++ b/.github/workflows/run_main_tests.yml @@ -0,0 +1,43 @@ +name: Run checks in main and release + +on: + pull_request: + branches: + - '*release*' + - main + +jobs: + ci: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ '3.9', '3.10', '3.11' ] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install -e .[dev] + - name: Run linter checks + run: flake8 . && interrogate --verbose . + - name: Run tests and coverage + run: coverage run -m unittest discover && coverage report + verify_version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Check version incremented + run: | + pkg_name=$(grep -P 'version = \{attr = .*\}' pyproject.toml | grep -oP '\w+.__version__') + init_file="./src/${pkg_name//.__version__}/__init__.py" + pkg_version=$(grep -Po '[0-9]+\.[0-9]+\.[0-9]+' "$init_file") + latest_tag=$(git ls-remote --tags --refs --sort="v:refname" | tail -n1 | sed 's/.*\///') + echo "Checking pkg_version v$pkg_version and latest_tag $latest_tag" + if [ "$latest_tag" == "v$pkg_version" ] + then + exit 1 + fi + echo "Versions are different"