Test reversibility of migrations (#220)
Some checks failed
Run unit tests / rubocop (push) Failing after 1m10s
Run unit tests / unit_tests (push) Failing after 1m16s
Run unit tests / copyright_notice (push) Successful in 1m16s
Run unit tests / check-licenses (push) Successful in 1m36s
Run unit tests / build-static-assets (push) Has been skipped

We want to make sure that:

1. Migrations are reversible
2. Reapplying migrations added to a PR leads to the same schema.rb

Reviewed-on: #220
Co-authored-by: Manuel Bustillo <bustikiller@bustikiller.com>
Co-committed-by: Manuel Bustillo <bustikiller@bustikiller.com>
This commit is contained in:
Manuel Bustillo 2025-01-25 09:43:43 +00:00 committed by bustikiller
parent 66aded5112
commit f414acb2d5
12 changed files with 134 additions and 127 deletions

View File

@ -1,46 +0,0 @@
name: Build Nginx-based docker image
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
build-static-assets:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to the private Docker registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.PRIVATE_REGISTRY_HOST }}
username: ${{ secrets.PRIVATE_REGISTRY_USERNAME }}
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
- name: Build and push intermediate stages (build)
uses: docker/build-push-action@v6
with:
context: .
target: build
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:build
cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:build
cache-to: type=inline
- name: Build and push (final)
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest
cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest
cache-to: type=inline

View File

@ -1,39 +0,0 @@
name: Add copyright notice
on:
pull_request:
permissions:
contents: write
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
copyright_notice:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.ACTIONS_TOKEN }}
ref: ${{ github.head_ref }}
- uses: VinnyBabuManjaly/copyright-action@v1.0.0
with:
CopyrightString: '# Copyright (C) 2024-2025 LibreWeddingPlanner contributors\n\n'
FileType: '.rb'
Path: 'app/, config/, db/, spec/'
- uses: VinnyBabuManjaly/copyright-action@v1.0.0
with:
CopyrightString: '<%# Copyright (C) 22024-2025 LibreWeddingPlanner contributors %>\n\n'
FileType: '.erb'
Path: 'app/'
- name: Commit changes
run: |
git config --local user.email "bustikiller@bustikiller.com"
git config --local user.name "Manuel Bustillo"
git add .
if [ -n "$(git status --porcelain)" ]; then
echo "there are changes";
git commit -m "Add copyright notice"
git push
else
echo "no changes";
fi

View File

@ -1,21 +0,0 @@
name: Check usage of free licenses
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
check-licenses:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: ruby/setup-ruby@v1.207.0
- name: Install project dependencies
run: bundle install --jobs `getconf _NPROCESSORS_ONLN`
- name: Run license finder
run: license_finder

View File

@ -10,7 +10,7 @@ concurrency:
jobs:
unit_tests:
runs-on: ubuntu-latest
services:
services: &services
postgres:
image: postgres
env:
@ -22,10 +22,11 @@ jobs:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.head_ref }} # Checkout the actual branch, not the result if merged into the base
- uses: ruby/setup-ruby@v1.207.0
- run: bundle install
- run: bundle exec rubocop --force-exclusion --parallel
- name: Wait until Postgres is ready to accept connections
- &postgres_wait
name: Wait until Postgres is ready to accept connections
run: |
apt-get update && apt-get install -f -y postgresql-client
until pg_isready -h postgres -U postgres -d postgres
@ -33,12 +34,126 @@ jobs:
sleep 1
echo "Trying again"
done
- run: |
- name: Load schema and run unit tests
run: |
bundle exec rake db:schema:load
bundle exec rspec
env:
RAILS_ENV: test
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
- name: Get all migrations added
id: changed-migration-files
uses: tj-actions/changed-files@v45
with:
files: |
db/migrate/**.rb
- name: Redo all migrations and check there are no schema changes
if: steps.changed-migration-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-migration-files.outputs.all_changed_files }}
RAILS_ENV: test
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
run: |
echo ${#ALL_CHANGED_FILES[@]} migrations changed:
for file in ${ALL_CHANGED_FILES}; do
echo "$file"
done
bundle exec rake db:migrate:redo STEP=${#ALL_CHANGED_FILES[@]}
git diff --exit-code db/schema.rb
- name: Clean up containers generated by this flow
if: failure()
run: docker ps --filter network=$JOB_CONTAINER_NAME-$GITHUB_JOB-network --filter name=$JOB_CONTAINER_NAME-* --format "{{.ID}}" | xargs docker rm -f
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: ruby/setup-ruby@v1.207.0
- run: bundle install
- run: bundle exec rubocop --force-exclusion --parallel
check-licenses:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: ruby/setup-ruby@v1.207.0
- name: Install project dependencies
run: bundle install --jobs `getconf _NPROCESSORS_ONLN`
- name: Run license finder
run: license_finder
copyright_notice:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.ACTIONS_TOKEN }}
ref: ${{ github.head_ref }}
- uses: VinnyBabuManjaly/copyright-action@v1.0.0
with:
CopyrightString: '# Copyright (C) 2024-2025 LibreWeddingPlanner contributors\n\n'
FileType: '.rb'
Path: 'app/, config/, db/, spec/'
IgnorePath: 'db'
- uses: VinnyBabuManjaly/copyright-action@v1.0.0
with:
CopyrightString: '<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>\n\n'
FileType: '.erb'
Path: 'app/'
- name: Commit changes
run: |
git config --local user.email "bustikiller@bustikiller.com"
git config --local user.name "Manuel Bustillo"
git add .
if [ -n "$(git status --porcelain)" ]; then
echo "there are changes";
git commit -m "Add copyright notice"
git push
else
echo "no changes";
fi
build-static-assets:
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- unit_tests
- rubocop
- check-licenses
- copyright_notice
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to the private Docker registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.PRIVATE_REGISTRY_HOST }}
username: ${{ secrets.PRIVATE_REGISTRY_USERNAME }}
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
- name: Build and push intermediate stages (build)
uses: docker/build-push-action@v6
with:
context: .
target: build
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:build
cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:build
cache-to: type=inline
- name: Build and push (final)
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest
cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest
cache-to: type=inline

View File

@ -1,6 +1,6 @@
<%# Copyright (C) 22024-2025 LibreWeddingPlanner contributors %>
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
<%<%<%<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

View File

@ -1,3 +1,3 @@
<%# Copyright (C) 22024-2025 LibreWeddingPlanner contributors %>
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
<%<%<%<%= yield %>
<%= yield %>

View File

@ -1,6 +1,6 @@
<%# Copyright (C) 22024-2025 LibreWeddingPlanner contributors %>
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
<%<%<%<p>Welcome <%= @email %>!</p>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>

View File

@ -1,6 +1,6 @@
<%# Copyright (C) 22024-2025 LibreWeddingPlanner contributors %>
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
<%<%<%<p>Hello <%= @email %>!</p>
<p>Hello <%= @email %>!</p>
<% if @resource.try(:unconfirmed_email?) %>
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>

View File

@ -1,5 +1,5 @@
<%# Copyright (C) 22024-2025 LibreWeddingPlanner contributors %>
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
<%<%<%<p>Hello <%= @resource.email %>!</p>
<p>Hello <%= @resource.email %>!</p>
<p>We're contacting you to notify you that your password has been changed.</p>

View File

@ -1,6 +1,6 @@
<%# Copyright (C) 22024-2025 LibreWeddingPlanner contributors %>
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
<%<%<%<p>Hello <%= @resource.email %>!</p>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>

View File

@ -1,6 +1,6 @@
<%# Copyright (C) 22024-2025 LibreWeddingPlanner contributors %>
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
<%<%<%<p>Hello <%= @resource.email %>!</p>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>

4
db/schema.rb generated
View File

@ -1,5 +1,3 @@
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
@ -39,7 +37,7 @@ ActiveRecord::Schema[8.0].define(version: 2024_12_16_231415) do
t.index "LEAST(group_a_id, group_b_id), GREATEST(group_a_id, group_b_id)", name: "uindex_group_pair", unique: true
t.index ["group_a_id"], name: "index_group_affinities_on_group_a_id"
t.index ["group_b_id"], name: "index_group_affinities_on_group_b_id"
t.check_constraint "discomfort >= 0::double precision AND discomfort <= 2::double precision"
t.check_constraint "discomfort >= 0::double precision AND discomfort <= 2::double precision", name: "check_valid_discomfort"
t.check_constraint "group_a_id <> group_b_id", name: "check_distinct_groups"
end