|
| 1 | +# Stolen from https://github.com/mrchief/aws-creds-okta-action/blob/master/.github/workflows/autorelease.yml |
| 2 | +name: Auto Release |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: |
| 7 | + - master |
| 8 | +jobs: |
| 9 | + github-release: |
| 10 | + if: github.event.pull_request.merged == true && contains(toJSON(github.event.pull_request.labels.*.name), '"autorelease"') |
| 11 | + runs-on: ubuntu-latest |
| 12 | + env: |
| 13 | + manifest_file: 'manifest.yml' |
| 14 | + changelog_file: 'CHANGELOG.md' |
| 15 | + outputs: |
| 16 | + version: ${{ steps.version.outputs.version }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v2 |
| 19 | + with: |
| 20 | + ref: master |
| 21 | + - name: get version |
| 22 | + id: version |
| 23 | + run: | |
| 24 | + sed -n 's/^version:\s\(.*\)$/\1/p' ${{ env.manifest_file }} | xargs -I {} echo "::set-output name=version::{}" |
| 25 | + - name: get changelog |
| 26 | + id: changelog |
| 27 | + run: | |
| 28 | + changelog=$(echo "${{ steps.version.outputs.version}}" | xargs -I {} sed -n '/^#\s'"{}"'.*$/,/^#\s\([^[:space:]]\+\).*$/{//!p}' ${{ env.changelog_file }}) |
| 29 | + echo $changelog |
| 30 | + changelog="${changelog//'%'/'%25'}" |
| 31 | + changelog="${changelog//$'\n'/'%0A'}" |
| 32 | + changelog="${changelog//$'\r'/'%0D'}" |
| 33 | + echo "::set-output name=changelog::$changelog" |
| 34 | + - name: echo version and changelog |
| 35 | + run: | |
| 36 | + echo "${{ steps.version.outputs.version}}" |
| 37 | + echo "${{ steps.changelog.outputs.changelog }}" |
| 38 | + - name: Create Release |
| 39 | + |
| 40 | + with: |
| 41 | + name: ${{ steps.version.outputs.version }} |
| 42 | + tag: v${{ steps.version.outputs.version }} |
| 43 | + body: ${{ steps.changelog.outputs.changelog}} |
| 44 | + draft: false |
| 45 | + prerelease: false |
| 46 | + # An optional tag for the release. If this is omitted the git ref will be used (if it is a tag). |
| 47 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + build-and-push-docker-image: |
| 50 | + needs: github-release |
| 51 | + runs-on: ubuntu-latest |
| 52 | + env: |
| 53 | + IMAGE_NAME: ${{github.repository}} |
| 54 | + permissions: |
| 55 | + contents: read |
| 56 | + packages: write |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Checkout repository |
| 60 | + uses: actions/checkout@v2 |
| 61 | + |
| 62 | + - name: Set up Docker Buildx |
| 63 | + uses: docker/setup-buildx-action@v1 |
| 64 | + |
| 65 | + - name: Cache Docker layers |
| 66 | + uses: actions/cache@v2 |
| 67 | + with: |
| 68 | + path: /tmp/.buildx-cache |
| 69 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 70 | + restore-keys: | |
| 71 | + ${{ runner.os }}-buildx- |
| 72 | + - name: Login to DockerHub |
| 73 | + uses: docker/login-action@v1 |
| 74 | + with: |
| 75 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 76 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Log in to the Container registry |
| 79 | + |
| 80 | + with: |
| 81 | + registry: ghcr.io |
| 82 | + username: ${{ github.actor }} |
| 83 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 84 | + |
| 85 | + - name: Extract metadata (tags, labels) for Docker |
| 86 | + id: meta |
| 87 | + |
| 88 | + with: |
| 89 | + images: ${{ env.IMAGE_NAME }},ghcr.io/${{ env.IMAGE_NAME }} |
| 90 | + tags: | |
| 91 | + type=semver,pattern={{version}},value=${{needs.github-release.outputs.version}} |
| 92 | + - name: Build and push Docker image |
| 93 | + |
| 94 | + with: |
| 95 | + context: . |
| 96 | + push: true |
| 97 | + tags: ${{ steps.meta.outputs.tags }} |
| 98 | + labels: ${{ steps.meta.outputs.labels }} |
| 99 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 100 | + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max |
| 101 | + |
| 102 | + - # Temp fix |
| 103 | + # https://github.com/docker/build-push-action/issues/252 |
| 104 | + # https://github.com/moby/buildkit/issues/1896 |
| 105 | + name: Move cache |
| 106 | + run: | |
| 107 | + rm -rf /tmp/.buildx-cache |
| 108 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments