Skip to content

sync-database

sync-database #9

Workflow file for this run

name: Sync Database
on:
repository_dispatch:
types:
- sync-database
# Permissions for terramform-init action
permissions:
id-token: write
contents: read
env:
WORKSPACE: "production"
jobs:
sync-database:
name: Sync Database
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Load env
id: env
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ] ; then
pr_branch_name="feat/sync-database-manual"
pr_body="Sync database: manualy triggered by ${{ github.actor }}"
hash_commit_awesome_italia_opensource="latest"
else
pr_branch_name="feat/sync-database-action-${{ github.event.client_payload.hash }}"
pr_body="Sync database: triggered by [awesome-italia-opensource](https://github.com/italia-opensource/awesome-italia-opensource) (pipeline: [${{ github.event.client_payload.run_id }}](https://github.com/italia-opensource/awesome-italia-opensource/actions/runs/${{ github.event.client_payload.run_id }}))"
hash_commit_awesome_italia_opensource="${{ github.event.client_payload.hash }}"
fi
echo "pr_branch_name=${pr_branch_name}" >> $GITHUB_OUTPUT
echo "pr_branch_name=${pr_branch_name}"
echo "pr_body=${pr_body}" >> $GITHUB_OUTPUT
echo "pr_body=${pr_body}"
echo "hash_commit_awesome_italia_opensource=${hash_commit_awesome_italia_opensource}" >> $GITHUB_OUTPUT
echo "hash_commit_awesome_italia_opensource=${hash_commit_awesome_italia_opensource}"
- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: "website/.nvmrc"
cache-dependency-path: website/yarn.lock
cache: "yarn"
- name: Terraform Init
id: terraform
uses: ./.github/workflows/actions/terraform-init
timeout-minutes: 5
with:
WORKSPACE: ${{ env.WORKSPACE }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_ROLE_NAME: ${{ secrets.AWS_ROLE_NAME }}
AWS_TERRAFORM_STATE_BUCKET: ${{ secrets.AWS_TERRAFORM_STATE_BUCKET }}
- name: Build
id: build
timeout-minutes: 5
run: |
make download HASH_COMMIT="${{ steps.env.outputs.hash_commit_awesome_italia_opensource}}"
git checkout HEAD -- infrastructure/.terraform.lock.hcl # Ignore changes to the lock file
status=$(git status -s)
echo "## Status"
echo "${status}"
# Skip build if only metadata.json has changed and the pipeline was triggered by awesome-italia-opensource
if [[ "${{ github.event_name }}" == "repository_dispatch" ]] && [[ "${status}" == " M website/database/metadata.json" ]] ; then
echo "has_changed=false" >> $GITHUB_OUTPUT
exit 0
fi
make setup-website VIRTUAL_ENV=false
make build
echo "has_changed=true" >> $GITHUB_OUTPUT
- name: Create Pull Request
if: ${{ steps.build.outputs.has_changed == 'true' }}
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.ACTION_WORKFLOWS }}
branch: ${{ steps.env.outputs.pr_branch_name }}
title: "feat(website): sync database"
body: ${{ steps.env.outputs.pr_body }}
commit-message: "feat(website): sync database"
author: "FabrizioCafolla <${{ secrets.ACTION_EMAIL }}>"
add-paths: |
website/src/*
website/database/*
- name: Update comment
if: ${{ success() && github.event.client_payload.slash_command.args.named.comment_id }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.ACTION_WORKFLOWS }}
comment-id: ${{ github.event.client_payload.slash_command.args.named.comment_id }}
reactions: hooray
- name: Failure
if: ${{ failure() && github.event.client_payload.slash_command.args.named.comment_id }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.ACTION_WORKFLOWS }}
comment-id: ${{ github.event.client_payload.slash_command.args.named.comment_id }}
body: |
:warning: Deployment failed. See #[${{ github.run_number }}](https://github.com/italia-opensource/italiaopensource.com/actions/runs/${{ github.run_id }}) for more details.