Skip to content

Commit

Permalink
Merge pull request #13 from lesteenman/release-flow
Browse files Browse the repository at this point in the history
Create releases from PR's to main to test more rapidly
  • Loading branch information
lesteenman authored Mar 7, 2021
2 parents 4b52d65 + a117e11 commit 20c761e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 95 deletions.
1 change: 1 addition & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: codeql

on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
Expand Down
79 changes: 0 additions & 79 deletions .github/workflows/deploy.yml

This file was deleted.

95 changes: 83 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: main

on:
push:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
push:
branches: [ main ]

jobs:
build:
Expand Down Expand Up @@ -34,7 +33,9 @@ jobs:
id: cached-discord-app-poetry
uses: actions/cache@v2
with:
path: discord_app/.venv
path: |
discord_app/.venv
discord_app/.serverless/cache
key: venv-${{ runner.os }}-${{ hashFiles('discord_app/poetry.lock') }}

- name: Poetry install for discord_app/
Expand Down Expand Up @@ -102,7 +103,7 @@ jobs:
name: infra
path: infra/

release:
deploy:
needs: build
runs-on: ubuntu-latest
steps:
Expand All @@ -112,30 +113,100 @@ jobs:
uses: actions/download-artifact@v2
with:
name: discord-app-package
path: discord_app/.serverless/

- name: Restore the artifact for the error-parser
uses: actions/download-artifact@v2
with:
name: error-parser-package
path: error_parser_function/.serverless/

- name: Restore the artifact for the error-parser
uses: actions/download-artifact@v2
- name: Install Python 3.8
uses: actions/setup-python@v1
with:
name: error-parser-package
python-version: 3.8

- name: Install poetry
uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv for infra
id: cached-infra-poetry
uses: actions/cache@v2
with:
path: infra/.venv
key: venv-${{ runner.os }}-${{ hashFiles('infra/poetry.lock') }}

- name: Poetry install for infra/
run: cd infra && poetry install
if: steps.cached-infra-poetry.outputs.cache-hit != 'true'

- name: Synthesize CDK
run: cd infra && poetry run npx cdk synth --output build/cdk.out
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_TARGET_ACCOUNT: ${{ secrets.AWS_TARGET_ACCOUNT }}
DISCORD_PUBLIC_KEY: ${{ secrets.DISCORD_PUBLIC_KEY }}
DISCORD_APPLICATION_ID: ${{ secrets.DISCORD_APPLICATION_ID }}
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
NOTIFICATION_EMAIL: ${{ secrets.NOTIFICATION_EMAIL }}

- name: Deploy CDK
run: cd infra && npx cdk synth --app ./build/cdk.out --require-approval never
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_TARGET_ACCOUNT: ${{ secrets.AWS_TARGET_ACCOUNT }}

release:
needs: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install poetry
uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Build Changelog
id: changes
run: echo "::set-output name=changeLog::$(git show --format=%B | tail +3)"
run: echo "::set-output name=changelog::$(git log --format=%B -1)"

- name: Get the base version
id: release_version
run: echo "::set-output name=version::$(cd discord_app && poetry version -s)"

- name: Get the date of the release
id: release_date
run: echo "::set-output name=date::$(date +"%Y-%m-%d")"

- name: Get the shorthash of the commit
id: release_hash
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: Check changelog
run: echo ${{ steps.changes.outputs.changelog }}

- name: Check release name
run: echo "v${{ steps.release_version.outputs.version }}.${{ steps.release_date.outputs.date }}.${{ steps.release_hash.outputs.sha_short }}"

- name: Create Release
uses: actions/create-release@v1
with:
tag_name: ${{ steps.release_name.outputs.date }} ${GITHUB_SHA::7}
release_name: ${{ steps.release_name.outputs.date }} ${GITHUB_SHA::7}
body: ${{steps.changes.outputs.changelog}}
tag_name: "v${{ steps.release_version.outputs.version }}.${{ steps.release_date.outputs.date }}.${{ steps.release_hash.outputs.sha_short }}"
release_name: "v${{ steps.release_version.outputs.version }}.${{ steps.release_date.outputs.date }}.${{ steps.release_hash.outputs.sha_short }}"
body: ${{ steps.changes.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 1 addition & 3 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: pull-requests

on:
workflow_dispatch:
pull_request:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion discord_app/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "discord_app"
version = "0.8.0"
version = "1.0"
description = ""
authors = ["lesteenman <[email protected]>"]

Expand Down

0 comments on commit 20c761e

Please sign in to comment.