Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from BerkeleyLibrary/docker-build
Browse files Browse the repository at this point in the history
Docker build fixup
  • Loading branch information
anarchivist authored Aug 9, 2024
2 parents b205027 + 12276bc commit e300eae
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 40 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Build
on:
- push
- pull_request
- workflow_dispatch
env:
REGISTRY: ghcr.io

permissions:
contents: read

jobs:
setup:
runs-on: ubuntu-latest

steps:
- name: Sanitize image name
uses: actions/github-script@v6
id: image-name
with:
result-encoding: string
script: return '${{ env.REGISTRY }}/${{ github.repository }}'.toLowerCase()
- name: Get short SHA
run: |
echo SHORT_SHA="${GITHUB_SHA:0:7}" >> $GITHUB_ENV
outputs:
base_image_name: ${{ steps.image-name.outputs.result }}
build_image: ${{ steps.image-name.outputs.result }}:${{ env.SHORT_SHA }}

build:
if: github.event_name != 'release'
needs: setup
env:
BUILD_IMAGE: ${{ needs.setup.outputs.build_image }}
runs-on: ubuntu-latest
permissions:
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get build start time
run: |
echo BUILD_TIMESTAMP="$(date --utc --iso-8601=seconds)" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ env.BUILD_IMAGE }}
build-args: |
BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }}
BUILD_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
DOCKER_TAG=${{ env.BUILD_IMAGE }}
GIT_BRANCH=${{ github.ref_name }}
GIT_COMMIT=${{ github.sha }}
GIT_URL=${{ github.repositoryUrl }}
outputs:
build_image: ${{ env.BUILD_IMAGE }}

test:
if: github.event_name != 'release'
needs: build
runs-on: ubuntu-latest
container:
image: ${{ needs.build.outputs.build_image }}
defaults:
run:
working-directory: /opt/app

steps:
- name: Run tests
run: bundle exec rake spec

- name: Run style checks
run: bundle exec rake rubocop

- name: Upload artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: artifacts
path: /opt/artifacts/**
32 changes: 0 additions & 32 deletions .github/workflows/ruby.yml

This file was deleted.

6 changes: 6 additions & 0 deletions lib/berkeley_library/deo_volente.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# frozen_string_literal: true

Dir.glob(File.expand_path('deo_volente/*.rb', __dir__)).each(&method(:require))

module BerkeleyLibrary
# A set of helper tools for loading data into the UC Berkeley Dataverse
module DeoVolente
end
end
12 changes: 4 additions & 8 deletions spec/lib/deo_volente/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'spec_helper'

module BerkeleyLibrary
# A set of helper tools for loading data into the UC Berkeley Dataverse
module DeoVolente
describe File do
let(:orig_filename) { 'spec/data/foo.csv' }
Expand All @@ -12,7 +13,6 @@ module DeoVolente
let(:fi_filename) { 'foo.csv' }
let(:fi_mime_type) { 'text/csv' }
let(:fi_md5) { '11f8e9dc8c473278962dbadfd803e4c1' }
let(:sid) { '1912f1446ad-0d909b10387' }

describe '#initialize' do
it 'creates a new instance' do
Expand All @@ -21,9 +21,9 @@ module DeoVolente

it 'creates a new instance with fully specified options' do
f = described_class.new(filename: 'spec/data/unrecognizable', md5_hash: 'md5', directory_label: 'bogus',
mime_type: 'application/json', storage_identifier: sid)
mime_type: 'application/json', storage_identifier: 'not_Real')
expect(f).to have_attributes(md5_hash: 'md5', directory_label: 'bogus', mime_type: 'application/json',
storage_identifier: sid)
storage_identifier: 'not_Real')
end
end

Expand Down Expand Up @@ -58,14 +58,10 @@ module DeoVolente
end

describe '#to_json' do
before do
file_instance.storage_identifier = sid
end

it 'returns a JSON object suitable for Dataverse' do
parsed = JSON.parse(file_instance.to_json)
expect(parsed).to include('md5Hash' => fi_md5, 'description' => '', 'fileName' => fi_filename,
'mimeType' => fi_mime_type, 'storageIdentifier' => "file://#{sid}")
'mimeType' => fi_mime_type, 'storageIdentifier' => match(%r{^file://}))
end
end
end
Expand Down

0 comments on commit e300eae

Please sign in to comment.