Skip to content

Commit

Permalink
Add CD (#6)
Browse files Browse the repository at this point in the history
* Add CD

* Fix offenses

* Fix version

* Fix version
  • Loading branch information
armandfardeau authored Feb 13, 2023
1 parent c495536 commit 0ef9641
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 13 deletions.
75 changes: 70 additions & 5 deletions .github/workflows/ci_cleaner.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
name: "[CI] Cleaner"
name: "CI/CD"
on: [push]

env:
CI: "true"
CODECOV: "true"
RUBY_VERSION: 3.1.1
NODE_VERSION: 16.9.1

jobs:
main:
lint:
name: Lint code
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: rokroskar/[email protected]
if: "github.ref != 'refs/heads/develop'"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- uses: actions/[email protected]
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run Rubocop
run: bundle exec rubocop -P
tests:
name: Tests
runs-on: ubuntu-latest
timeout-minutes: 30
Expand Down Expand Up @@ -55,9 +73,14 @@ jobs:
- run: mkdir -p ./spec/decidim_dummy_app/tmp/screenshots
name: Create the screenshots folder
- uses: nanasess/[email protected]
- run: RAILS_ENV=test bundle exec rails assets:precompile
name: Precompile assets
working-directory: ./spec/decidim_dummy_app/
- name: Run precompile if needed
run: |
if [[ -d "app/views" ]] || [[ -d "spec/mailers" ]] || [[ -d "spec/system" ]]; then
cd "spec/decidim_dummy_app"
bundle exec rails assets:precompile
else
echo "No need to precompile assets since system folder is empty"
fi
- run: bundle exec rspec
name: RSpec
- uses: codecov/codecov-action@v1
Expand All @@ -67,3 +90,45 @@ jobs:
name: screenshots
path: ./spec/decidim_dummy_app/tmp/screenshots
if-no-files-found: ignore
release:
if: "github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'"
needs: [tests, lint]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Setup git and gh
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
- run: gem install parse_gemspec-cli
name: Intall gem parser
- run: echo "::set-output name=tag::$(parse-gemspec-cli *.gemspec | jq .'version')"
name: Set tag version
id: set_tag
- name: Add tag and push
run: |
git tag
git push --tags
- name: Create release
run: gh release create ${{ steps.set_tag.outputs.tag }} --generate-notes
publish:
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Publish to RubyGems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push *.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/pkg/
/spec/reports/
/tmp/
.rubocop-https---raw-githubusercontent-com*

# rspec failure tracking
.rspec-failures
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ GIT
PATH
remote: .
specs:
decidim-cleaner (0.28.0.dev)
decidim-core (= 0.28.0.dev)
decidim-cleaner (0.1.0)
decidim-core (~> 0.28.0.dev)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/decidim/cleaner/clean_admin_logs_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CleanAdminLogsJob < ApplicationJob

def perform
Decidim::Organization.find_each do |organization|
return unless organization.delete_admin_logs?
next unless organization.delete_admin_logs?

Decidim::ActionLog.where(organization:).where("created_at < ?", Time.zone.now - (organization.delete_admin_logs_after || 365).days).delete_all
end
Expand Down
5 changes: 2 additions & 3 deletions app/jobs/decidim/cleaner/clean_inactive_users_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ class CleanInactiveUsersJob < ApplicationJob

def perform
Decidim::Organization.find_each do |organization|
return unless organization.delete_inactive_users?
next unless organization.delete_inactive_users?

send_warning(Decidim::User.where(organization:)
.where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days)
.where("last_sign_in_at > ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days - 1.day)
)
.where("last_sign_in_at > ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days - 1.day))
delete_user_and_send_email(Decidim::User.where(organization:).where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_after || 390).days))
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddDeleteInactiveUsersToOrganization < ActiveRecord::Migration[6.1]
def change
add_column :decidim_organizations, :delete_inactive_users, :boolean, default: false, null: false
Expand Down
2 changes: 1 addition & 1 deletion decidim-cleaner.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Gem::Specification.new do |s|

s.files = Dir["{app,config,db,lib}/**/*", "LICENSE-AGPLv3.txt", "Rakefile", "README.md"]

s.add_dependency "decidim-core", Decidim::Cleaner.version
s.add_dependency "decidim-core", "~> #{Decidim::Cleaner.decidim_version}"
end
4 changes: 4 additions & 0 deletions lib/decidim/cleaner/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module Decidim
# This holds the decidim-meetings version.
module Cleaner
def self.version
"0.1.0"
end

def self.decidim_version
"0.28.0.dev"
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/decidim/cleaner/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ module Decidim
subject { described_class }

it "has version" do
expect(subject.version).to eq("0.28.0.dev")
expect(subject.version).to eq("0.1.0")
end

it "has decidim version compatibility" do
expect(subject.decidim_version).to eq("0.28.0.dev")
end
end
end

0 comments on commit 0ef9641

Please sign in to comment.