build: use one common workflow (#478) #643
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: Deploy | |
on: | |
push: | |
branches: [main] | |
release: | |
types: [created] | |
workflow_dispatch: | |
env: | |
php-version: '8.2' | |
jobs: | |
############# | |
# Build | |
############# | |
build: | |
uses: monicahq/workflows/.github/workflows/build_assets.yml@main | |
with: | |
node-version: 18 | |
store: true | |
###################### | |
# Deploy on fortrabbit | |
###################### | |
deploy: | |
runs-on: ubuntu-latest | |
name: Deploy | |
needs: build | |
if: github.event_name != 'pull_request' | |
environment: fortrabbit | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Download assets | |
uses: actions/download-artifact@v4 | |
with: | |
name: assets | |
path: public/build | |
- name: Configure Git | |
run: | | |
git config user.email $GIT_EMAIL | |
git config user.name $GIT_USERNAME | |
env: | |
GIT_EMAIL: ${{ secrets.GIT_EMAIL }} | |
GIT_USERNAME: ${{ secrets.GIT_USERNAME }} | |
- name: Create release files | |
run: | | |
echo ${{ needs.build.outputs.version }} | tee config/.version | |
echo ${{ needs.build.outputs.release }} | tee config/.release | |
echo $GITHUB_SHA | tee config/.commit | |
- name: Update .htaccess | |
run: cp -f resources/.htaccess_production public/.htaccess | |
- name: Commit everything | |
run: | | |
git add -A --force public config | |
git commit -m "Build $($CURRENT_DATE_TIME)" | |
env: | |
CURRENT_DATE_TIME: "date +%Y-%m-%d:%H-%M" | |
- name: Deploy | |
run: | | |
git remote add deploy $REPO_URL | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
git push deploy $branch:master --force | |
env: | |
# This avoids a failure when the client does not know the SSH Host already | |
GIT_SSH_COMMAND: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" | |
REPO_URL: ${{ secrets.REPO_URL }} | |
############################ | |
# Create a release on sentry | |
############################ | |
sentry: | |
runs-on: ubuntu-latest | |
name: Sentry release | |
needs: build | |
if: github.event_name != 'pull_request' | |
environment: fortrabbit-sentry | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download assets | |
uses: actions/download-artifact@v4 | |
with: | |
name: assets | |
path: public/build | |
- name: Download source maps | |
uses: actions/download-artifact@v4 | |
with: | |
name: sourcemaps | |
path: public/build | |
- name: Create Sentry release | |
uses: getsentry/action-release@v1 | |
env: | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
SENTRY_ORG: ${{ secrets.SENTRY_ORG }} | |
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} | |
with: | |
environment: ${{ secrets.SENTRY_ENVIRONMENT }} | |
sourcemaps: public/build/assets/app.*.js public/build/assets/app.*.js.map | |
version: ${{ needs.build.outputs.release }} | |
url_prefix: ~/js |