|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: Docker Publish Release |
| 4 | + |
| 5 | +# Controls when the action will run. |
| 6 | +on: |
| 7 | + release: |
| 8 | + # Want to run the automation when a release is created |
| 9 | + types: ['created'] |
| 10 | + |
| 11 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 12 | +jobs: |
| 13 | + # This workflow contains a single job called "build" |
| 14 | + docker-prod-release: |
| 15 | + # The type of runner that the job will run on |
| 16 | + runs-on: ubuntu-latest |
| 17 | + # You could use the following lines to help make sure only X people start the workflow |
| 18 | + # if: github.actor == 'admiralawkbar' || github.actor == 'jwiebalk' |
| 19 | + |
| 20 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 21 | + steps: |
| 22 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 23 | + - name: Checkout source code |
| 24 | + uses: actions/checkout@v2 |
| 25 | + |
| 26 | + ######################### |
| 27 | + # Install Docker BuildX # |
| 28 | + ######################### |
| 29 | + - name: Install Docker BuildX |
| 30 | + uses: docker/setup-buildx-action@v1 |
| 31 | + |
| 32 | + ###################################### |
| 33 | + # Login to GitHub Container Registry # |
| 34 | + ###################################### |
| 35 | + - name: Login to GitHub Container registry |
| 36 | + uses: docker/login-action@v1 |
| 37 | + with: |
| 38 | + registry: ghcr.io |
| 39 | + username: ${{ secrets.GCR_USERNAME }} |
| 40 | + password: ${{ secrets.GCR_TOKEN }} |
| 41 | + |
| 42 | + # Update deployment API |
| 43 | + - name: start deployment |
| 44 | + |
| 45 | + id: deployment |
| 46 | + with: |
| 47 | + step: start |
| 48 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + env: Release |
| 50 | + |
| 51 | + # Create a GitHub Issue with the info from this build |
| 52 | + - name: Create GitHub Issue |
| 53 | + |
| 54 | + id: create-issue |
| 55 | + with: |
| 56 | + # https://octokit.github.io/rest.js/v18#issues-create |
| 57 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 58 | + script: | |
| 59 | + const create = await github.issues.create({ |
| 60 | + owner: context.repo.owner, |
| 61 | + repo: context.repo.repo, |
| 62 | + title: "Deploying to production", |
| 63 | + body: 'Currently deploying a release...' |
| 64 | + }) |
| 65 | + console.log('create', create) |
| 66 | + return create.data.number |
| 67 | +
|
| 68 | + ########################################### |
| 69 | + # Build and Push containers to registries # |
| 70 | + ########################################### |
| 71 | + - name: Build and push |
| 72 | + uses: docker/build-push-action@v2 |
| 73 | + with: |
| 74 | + context: . |
| 75 | + file: ./Dockerfile |
| 76 | + push: true |
| 77 | + tags: | |
| 78 | + ghcr.io/lukaspersonal/containers:latest |
| 79 | + ghcr.io/lukaspersonal/containers:${{ github.event.release.tag_name }} |
| 80 | +
|
| 81 | + # Update Deployment API |
| 82 | + - name: update deployment status |
| 83 | + |
| 84 | + if: always() |
| 85 | + with: |
| 86 | + step: finish |
| 87 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + status: ${{ job.status }} |
| 89 | + deployment_id: ${{ steps.deployment.outputs.deployment_id }} |
| 90 | + env_url: https://github.com/orgs/${{github.repository_owner}}/packages?repo_name=${{github.repository.name}} |
| 91 | + |
| 92 | + - name: Update issue success |
| 93 | + |
| 94 | + if: success() |
| 95 | + with: |
| 96 | + # https://octokit.github.io/rest.js/v18#issues-create |
| 97 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 98 | + script: | |
| 99 | + github.issues.createComment({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + issue_number: "${{ steps.create-issue.outputs.result }}", |
| 103 | + title: "New issue created", |
| 104 | + body: "Successful!y deployed production" |
| 105 | + }) |
| 106 | +
|
| 107 | + - name: Update issue failure |
| 108 | + |
| 109 | + if: failure() |
| 110 | + with: |
| 111 | + # https://octokit.github.io/rest.js/v18#issues-create |
| 112 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 113 | + script: | |
| 114 | + github.issues.createComment({ |
| 115 | + owner: context.repo.owner, |
| 116 | + repo: context.repo.repo, |
| 117 | + issue_number: "${{ steps.create-issue.outputs.result }}", |
| 118 | + title: "New issue created", |
| 119 | + body: "Failed to deploy to production" |
| 120 | + }) |
0 commit comments