|
| 1 | +# This is an action that runs when an Airbyte version bump is merged into master. |
| 2 | +# It fetches the changelog from the version bump PR and automatically creates a |
| 3 | +# Release for the version bump. |
| 4 | +name: Create Release |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +jobs: |
| 12 | + create-release: |
| 13 | + if: startsWith(github.event.head_commit.message, 'Bump Airbyte version') |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: read |
| 18 | + steps: |
| 19 | + - name: Fetch Version Bump PR Body |
| 20 | + id: fetch_pr_body |
| 21 | + env: |
| 22 | + COMMIT_ID: ${{ github.event.head_commit.id }} |
| 23 | + shell: bash |
| 24 | + run: |- |
| 25 | + set -x |
| 26 | + PR=$(curl \ |
| 27 | + -H "Accept: application/vnd.github.v3+json" \ |
| 28 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 29 | + https://api.github.com/repos/${{ github.repository }}/commits/$COMMIT_ID/pulls) |
| 30 | + # The printf helps escape characters so that jq can parse the output. |
| 31 | + # The sed removes carriage returns so that the body is easier to parse later, and |
| 32 | + # escapes backticks so that they are not executed as commands. |
| 33 | + PR_BODY=$(printf '%s' "$PR" | jq '.[0].body' | sed 's/\\r//g' | sed 's/`/\\`/g') |
| 34 | + echo ::set-output name=pr_body::${PR_BODY} |
| 35 | + - name: Extract Changelog |
| 36 | + id: extract_changelog |
| 37 | + shell: bash |
| 38 | + run: |- |
| 39 | + set -x |
| 40 | + PR_BODY=${{ steps.fetch_pr_body.outputs.pr_body}} |
| 41 | + if [[ $PR_BODY = "null" ]]; then |
| 42 | + echo "No PR body exists for this commit, so a release cannot be generated." |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + # this regex extracts just the changelog contents |
| 46 | + if [[ $PR_BODY =~ Changelog:(\\n)*(.*)\\n\\n ]]; then |
| 47 | + CHANGELOG="${BASH_REMATCH[2]}" |
| 48 | + else |
| 49 | + echo "PR body does not match the changelog extraction regex" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + # save CHANGELOG into a multiline env var on the action itself, since Github Actions do not support outputting multiline strings well |
| 53 | + echo "CHANGELOG<<EOF" >> $GITHUB_ENV |
| 54 | + echo -e "$CHANGELOG" >> $GITHUB_ENV |
| 55 | + echo "EOF" >> $GITHUB_ENV |
| 56 | + - name: Checkout Airbyte |
| 57 | + uses: actions/checkout@v2 |
| 58 | + - name: Get Version |
| 59 | + id: get_version |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + VERSION=$(grep -w VERSION .env | cut -d"=" -f2) |
| 63 | + echo ::set-output name=VERSION::${VERSION} |
| 64 | + - name: Create Release |
| 65 | + id: create_release |
| 66 | + uses: ncipollo/release-action@v1 |
| 67 | + with: |
| 68 | + body: ${{ env.CHANGELOG }} |
| 69 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + prerelease: true |
| 71 | + tag: v${{ steps.get_version.outputs.VERSION }} |
0 commit comments