Merge pull request #50 from guillaume-sainthillier/app-update #125
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build And Deploy Release | |
on: | |
pull_request: | |
push: | |
branches: | |
- 'refs/pull/*' | |
tags: | |
- v* | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get all latest versions | |
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }} | |
run: | | |
echo TAG_VERSION=latest >> $GITHUB_ENV | |
echo APP_VERSION=latest >> $GITHUB_ENV | |
echo APP_VERSIONS=latest >> $GITHUB_ENV | |
- name: Get all stable versions | |
if: ${{ startsWith(github.ref, 'refs/tags/v') }} | |
run: | | |
echo TAG_VERSION=stable >> $GITHUB_ENV | |
echo APP_VERSION=$(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g" | sed -E "s/v?([0-9]+)\.([0-9]+)\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?/\1.\2.\3\4/g") >> $GITHUB_ENV | |
echo APP_VERSIONS=stable,$(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g" | sed -E "s/v?([0-9]+)\.([0-9]+)\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?/\1.\2.\3\4 \1.\2\4 \1\4/g") >> $GITHUB_ENV | |
- name: Publish to Docker Repository | |
uses: elgohr/Publish-Docker-Github-Action@v5 | |
with: | |
name: guystlr/by-night | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
buildargs: APP_VERSION | |
tags: '${{ env.APP_VERSIONS }}' | |
upload-assets: | |
needs: build | |
runs-on: ubuntu-latest | |
if: ${{ startsWith(github.ref, 'refs/tags/v') }} | |
container: | |
image: guystlr/by-night | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: eu-west-3 | |
steps: | |
- name: Upload assets to S3 | |
run: | | |
set -ex; | |
apk add --no-cache aws-cli; | |
aws s3 sync /app/public/build s3://assets.by-night.fr/build --size-only; | |
aws s3 sync /app/public/bundles s3://assets.by-night.fr/bundles --size-only | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- name: Deploy to production | |
uses: appleboy/ssh-action@master | |
env: | |
BY_NIGHT_PATH: ${{ secrets.BY_NIGHT_PATH }} | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
envs: BY_NIGHT_PATH | |
script_stop: true | |
script: | | |
cd $BY_NIGHT_PATH | |
sudo /bin/bash ./deploy.sh |