From 5d178a6d081031a94333fdccc8368626c820320a Mon Sep 17 00:00:00 2001 From: Jason Kai Date: Thu, 17 Aug 2023 09:43:19 -0400 Subject: [PATCH] switch to reusable workflows - Renamed deploy_docker.yml -> deploy.yml to be more generic (in case pypi deployment also wants to be added in the future) - Set docker deployment reuseable wf to inherit docker auth secrets --- .github/workflows/assign_reviewers.yml | 10 +--- .github/workflows/bump_version.yml | 63 ++------------------- .github/workflows/deploy.yml | 12 ++++ .github/workflows/deploy_docker.yml | 42 -------------- .github/workflows/release.yml | 76 +++----------------------- 5 files changed, 25 insertions(+), 178 deletions(-) create mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/deploy_docker.yml diff --git a/.github/workflows/assign_reviewers.yml b/.github/workflows/assign_reviewers.yml index f016a791..b70f871c 100644 --- a/.github/workflows/assign_reviewers.yml +++ b/.github/workflows/assign_reviewers.yml @@ -4,11 +4,5 @@ on: pull_request_target: types: [opened, ready_for_review] jobs: - assign: - runs-on: ubuntu-latest - if: github.event.pull_request.assignee == null - steps: - - name: Assign reviewer - uses: kentaro-m/auto-assign-action@v1.2.4 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} + assign-reviewer: + uses: khanlab/actions/.github/workflows/assign_reviewers.yml@main diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml index 2b5c23fc..f08ab234 100644 --- a/.github/workflows/bump_version.yml +++ b/.github/workflows/bump_version.yml @@ -4,63 +4,8 @@ on: pull_request_target: types: [closed] jobs: - build: + bump-version: if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - name: Checkout master branch - uses: actions/checkout@master - with: - ref: ${{ github.event.pull_request.base.ref }} - - name: Update changelog - uses: release-drafter/release-drafter@v5 - id: release-drafter - with: - commitish: ${{ github.event.pull_request.base.ref }} - env: - GITHUB_TOKEN: ${{ secrets.BP_PAT_TOKEN }} - - name: Get previous release version - run: | - echo "PREV_VER=$(cat pyproject.toml | grep -o -E '(version\s=\s)([[:punct:]])([0-9]+\.[0-9]+\.[0-9]+.+)([[:punct:]])' | cut -d ' ' -f 3 | tr -d '"')" >> $GITHUB_ENV - - name: Get previous bump version - env: - PREV_VER: ${{ env.PREV_VER }} - run: | - if [[ "$PREV_VER" != *"-pre."* ]]; then - echo "OLD_BUMP=0" >> $GITHUB_ENV - else - echo "OLD_BUMP=$(echo $PREV_VER | cut -d '.' -f 4)" >> $GITHUB_ENV - fi - - name: Bump version - env: - BUMP_VER: ${{ env.OLD_BUMP }} - run: | - echo "NEW_BUMP=$(($BUMP_VER + 1))" >> $GITHUB_ENV - - name: Set new release version - env: - RD_RELEASE: ${{ steps.release-drafter.outputs.name }} - run: | - if [ ! -z "$RD_RELEASE" ]; then - echo "NEW_RELEASE=$RD_RELEASE" >> $GITHUB_ENV - else - echo "NEW_RELEASE=0.1.0" >> $GITHUB_ENV - fi - - name: Update version in pyproject.toml - uses: jacobtomlinson/gha-find-replace@master - with: - include: pyproject.toml - find: version = "(?:([0-9]+\.[0-9]+\.[0-9]+.+)|([0-9]+\.[0-9]+\.[0-9]+))" - replace: version = "${{ env.NEW_RELEASE }}-pre.${{ env.NEW_BUMP }}" - - name: Commit updates - env: - SNAKEBIDS_VERSION: ${{ env.NEW_RELEASE }}-pre.${{ env.NEW_BUMP }} - run: | - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git diff-index --quiet HEAD || git commit -m "Bump version to $SNAKEBIDS_VERSION" -a - - name: Push changes - uses: CasperWA/push-protected@v2 - with: - branch: ${{ github.event.pull_request.base.ref }} - token: ${{ secrets.BP_PAT_TOKEN }} - unprotect_reviews: true + uses: khanlab/actions/.github/workflows/versioning/gh_semver.yml@main + secrets: + BP_PAT: ${{ secrets.BP_PAT_TOKEN }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..84d8b6b2 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,12 @@ +--- +name: Deploy packages +on: + workflow_dispatch: + push: + tags: [v*] +jobs: + deploy_docker: + uses: khanlab/actions/.github/workflows/release/docker.yml@main + with: + maximize_space: true + secrets: inherit diff --git a/.github/workflows/deploy_docker.yml b/.github/workflows/deploy_docker.yml deleted file mode 100644 index 91bf2a2d..00000000 --- a/.github/workflows/deploy_docker.yml +++ /dev/null @@ -1,42 +0,0 @@ ---- -name: Deploy docker container -on: - workflow_dispatch: - push: - tags: [v*] -jobs: - deploy_docker: - name: Docker deploy - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - steps: - - name: Maximize build space - uses: easimon/maximize-build-space@master - with: - remove-android: 'true' # android-sdk - remove-codeql: 'true' # code scanning - remove-dotnet: 'true' # .net sdk - remove-haskell: 'true' # haskell - remove-docker-images: 'true' # rm existing cached images - overprovision-lvm: 'true' # let "overuse" of set disk space - - name: Checkout repo - uses: actions/checkout@master - - name: Get metadata - uses: docker/metadata-action@v4.1.1 - id: metadata - with: - images: ${{ github.repository }} - - name: Login to Dockerhub - uses: docker/login-action@v2.1.0 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.metadata.outputs.tags }} - labels: ${{ steps.metadata.outputs.labels }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae1e6ff8..a8a8284a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,72 +7,10 @@ on: description: Comments required: false jobs: - release_changelog: - runs-on: ubuntu-latest - steps: - - name: Print author - run: | - echo "Author: ${{ github.triggering_actor }}" - echo "Comments: ${{ github.event.inputs.comments }}" - - name: Extract branch name - shell: bash - id: extract_branch - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - - uses: actions/checkout@master - with: - ref: ${{ steps.extract_branch.outputs.branch }} - - name: Draft change log - uses: release-drafter/release-drafter@v5 - id: release-drafter - with: - commitish: ${{ steps.extract_branch.outputs.branch }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Set new release version - env: - RD_RELEASE: ${{ steps.release-drafter.outputs.name }} - run: | - if [ ! -z "$RD_RELEASE" ]; then - echo "NEW_RELEASE=$RD_RELEASE" >> $GITHUB_ENV - else - echo "NEW_RELEASE=0.1.0" >> $GITHUB_ENV - fi - - name: Update pipeline description - uses: jacobtomlinson/gha-find-replace@master - with: - include: scattr/pipeline_description.json - find: '"Version": "(?:([0-9]+\.[0-9]+\.[0-9]+.+)|([0-9]+\.[0-9]+\.[0-9]+))"' - replace: '"Version": "${{ env.NEW_RELEASE }}"' - - name: Update version in pyproject.toml - uses: jacobtomlinson/gha-find-replace@master - with: - include: pyproject.toml - find: version = "(?:([0-9]+\.[0-9]+\.[0-9]+.+)|([0-9]+\.[0-9]+\.[0-9]+))" - replace: version = "${{ env.NEW_RELEASE }}" - - name: Update container version - uses: jacobtomlinson/gha-find-replace@master - with: - include: scattr/config/snakebids.yml - find: 'scattr: "docker://khanlab/scattr:v(?:([0-9]+\.[0-9]+\.[0-9]+.+)|([0-9]+\.[0-9]+\.[0-9]+))"' - replace: 'scattr: "docker://khanlab/scattr:v${{ env.NEW_RELEASE }}"' - - name: Commit updates - env: - LATEST_VERSION: ${{ env.NEW_RELEASE }} - run: | - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git diff-index --quiet HEAD || git commit -m "Bump version to $LATEST_VERSION" -a - - name: Push changes - uses: CasperWA/push-protected@v2 - with: - token: ${{ secrets.BP_PAT_TOKEN }} - unprotect_reviews: true - - name: Publish change log - uses: release-drafter/release-drafter@v5 - with: - commitish: ${{ steps.extract_branch_outputs.branch }} - publish: true - name: ${{ env.NEW_RELEASE }} - tag: v${{ env.NEW_RELEASE }} - env: - GITHUB_TOKEN: ${{ secrets.BP_PAT_TOKEN }} + release_package: + uses: khanlab/actions/.github/workflows/release/gh_release.yml@main + with: + comments: ${{ github.event.inputs.comments }} + pipeline_description: true + secrets: + BP_PAT: ${{ secrets.BP_PAT_TOKEN }}