|
| 1 | +name: Build and push container image to GHCR |
| 2 | + |
| 3 | +# Run this workflow whenever a Dockerfile is updated. |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + - 'workflows/Nextflow/modules/runAssembly/Dockerfile' |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-and-push-image: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout branch |
| 17 | + uses: actions/checkout@v4 |
| 18 | + - name: Get Version |
| 19 | + id: get_version |
| 20 | + run: | |
| 21 | + VERSION=$(grep -oP 'version=\K.*' workflows/Nextflow/modules/runAssembly/Dockerfile) |
| 22 | + VERSION=${VERSION:-1.0.0} |
| 23 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 24 | + - name: Authenticate with container registry |
| 25 | + uses: docker/login-action@v3 |
| 26 | + with: |
| 27 | + registry: ghcr.io |
| 28 | + username: ${{ github.actor }} |
| 29 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + # Use the `docker/build-push-action` action to build the image described |
| 31 | + # by the specified Dockerfile. If the build succeeds, push the image to GHCR. |
| 32 | + # This action uses the `tags` parameters to tag the image with the Git tag name |
| 33 | + # the image, respectively, with the output from the "get_version" step above. |
| 34 | + # For more info: https://github.com/docker/build-push-action#usage. |
| 35 | + - name: Build and push container image |
| 36 | + id: push |
| 37 | + uses: docker/build-push-action@v5 |
| 38 | + with: |
| 39 | + context: . |
| 40 | + file: workflows/Nextflow/modules/runAssembly/Dockerfile |
| 41 | + push: true |
| 42 | + tags: ghcr.io/lanl-bioinformatics/edge_run_assembly:${{ steps.get_version.outputs.version }} |
| 43 | + - name: update image tag ID and version in the config |
| 44 | + run: | |
| 45 | + imageName="ghcr.io/lanl-bioinformatics/edge_run_assembly:${{ steps.get_version.outputs.version }}" |
| 46 | + version="${{ steps.get_version.outputs.version }}" |
| 47 | + sed -i -E "s#apwat/run_assembly:[0-9a-zA-Z._-]+#${imageName}#" workflows/Nextflow/configs/container.config |
| 48 | + sed -i -E "s#edge_run_assembly:[0-9a-zA-Z._-]+#edge_run_assembly:${version}#" workflows/Nextflow/configs/container.config |
| 49 | + #A GitHub Action to detect changed files during a Workflow run and to commit and push them back to the GitHub repository. |
| 50 | + #By default, the commit is made in the name of "GitHub Actions" and co-authored by the user that made the last commit. |
| 51 | + - name: auto-commit image version update |
| 52 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 53 | + with: |
| 54 | + branch: auto-update-${{ github.run_id }} |
| 55 | + create_branch: true |
| 56 | + commit_message: "Auto update of run assembly docker image version ${{ steps.get_version.outputs.version }}" |
| 57 | + - name: Create Pull Request |
| 58 | + run: | |
| 59 | + title="Automated PR: update assembly docker image version ${{ steps.get_version.outputs.version }}" |
| 60 | + gh pr create \ |
| 61 | + --base main \ |
| 62 | + --head auto-update-${{ github.run_id }} \ |
| 63 | + --title "$title" \ |
| 64 | + --body "Created by GitHub Action" |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments