Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: Publish OCI Container
on: # yamllint disable-line rule:truthy
workflow_call:
inputs:
tag:
description: 'The tag to use for the container image'
required: false
type: string
workflow_dispatch:
inputs:
tag:
description: 'The tag to use for the container image'
required: false
type: string
jobs:
publish_github:
name: Publish the container image to GitHub Container Registry
runs-on: ubuntu-latest
strategy:
# Go hard on the builders
max-parallel: 5
matrix:
alpine-version: ['3.20']
ruby-version: ['3.4.1']
steps:
-
name: Checkout repository
uses: actions/checkout@v4
-
name: Publish to ghcr.io
env:
ALPINE_VERSION: ${{ matrix.alpine-version }}
REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUBY_VERSION: ${{ matrix.ruby-version }}
TAG: ${{ github.event.inputs.tag || '' }}
TRACE: ${{ secrets.ACTIONS_STEP_DEBUG || 'false' }}
# yamllint disable rule:line-length
run: |
if [ -z "$TAG" ]
then
[ "$TRACE" = true ] && printf 'No tag provided, getting tag from .version.txt\n' >&2
if [ -f ".version.txt" ]
then
version=$(<.version.txt)
else
[ "$TRACE" = true ] && printf 'No .version.txt found, getting version from git describe --tags --abbrev=0\n' >&2
version=$(git describe --tags --abbrev=0)
fi
else
[ "$TRACE" = true ] && printf 'Using provided tag %s\n' "$TAG" >&2
version=$TAG
fi
[ "$TRACE" = 'true' ] && printf 'Calling ./ci/build_image.sh -vvp "%s"\n' "$version" >&2
IMAGE_NAME=$(basename "$GITHUB_REPOSITORY") \
GITHUB_TOKEN=$REGISTRY_TOKEN \
ALPINE_VERSION=$ALPINE_VERSION \
RUBY_VERSION=$RUBY_VERSION \
./ci/build_image.sh -vvp "$version"
# yamllint enable rule:line-length
shell: bash
63 changes: 63 additions & 0 deletions .github/workflows/conventional_commits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: Conventional Commits And PR titles

on: # yamllint disable-line rule:truthy
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
comventional_commits:
name: Validate Commit Subjects
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: webiny/[email protected]
name: Validate Commit Subjects
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# All of the Angular commit types are allowed by default.
# Added types to this:
# * eyes - For observability related changes
# * sec - For security related changes
allowed-commit-types: "build,chore,ci,docs,eyes,feat,fix,perf,refactor,revert,sec,style,test" # yamllint disable-line rule:line-length
conventional_pr_title:
name: Validate PR title
runs-on: ubuntu-latest
steps:
-
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: validate-pr-title
name: Validate PR title
uses: amannn/action-semantic-pull-request@v5
with:
# All of the Angular commit types are allowed by default.
# Added types to this:
# * eyes - For observability related changes
# * sec - For security related changes
types: |
build
chore
ci
docs
eyes
feat
fix
perf
refactor
revert
sec
style
test
# We don't enforce scopes
# scopes:
# - frontend
# - backend
# - ci
# We don't disallow any scopes
# disallowScopes: |
# release
wip: true
36 changes: 36 additions & 0 deletions .github/workflows/gem.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Publish Ruby Gem
on: # yamllint disable-line rule:truthy
workflow_call:
workflow_dispatch:
jobs:
publish_gem:
name: Publish the gem to registries
runs-on: ubuntu-latest
strategy:
matrix:
registry:
- key: rubygems
secret: RUBYGEMS_TOKEN
- key: github
secret: GEM_TOKEN_GITHUB
steps:
-
name: Checkout repository
uses: actions/checkout@v4
-
name: Set up Ruby
uses: ruby/setup-ruby@v1

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Publish Ruby Gem' step
Uses Step
uses 'ruby/setup-ruby' with ref 'v1', not a pinned commit hash
with:
ruby-version: 3.4.1
bundler-cache: false
-
name: Publish to ${{ matrix.registry }}
env:
TRACE: ${{ secrets.ACTIONS_STEP_DEBUG || 'false' }}
GEM_TOKEN: ${{ secrets[matrix.registry.secret] }}

Check warning

Code scanning / CodeQL

Excessive Secrets Exposure Medium

All organization and repository secrets are passed to the workflow runner in
secrets[matrix.registry.secret]

Copilot Autofix

AI 11 months ago

To fix the problem, we need to avoid dynamically accessing secrets and instead explicitly specify the secrets required for each registry. This can be achieved by using conditional statements to set the appropriate secret based on the matrix configuration.

  • Modify the workflow to explicitly set the GEM_TOKEN environment variable based on the matrix.registry.key.
  • Use conditional statements to set the GEM_TOKEN for each registry.
Suggested changeset 1
.github/workflows/gem.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/gem.yaml b/.github/workflows/gem.yaml
--- a/.github/workflows/gem.yaml
+++ b/.github/workflows/gem.yaml
@@ -30,4 +30,4 @@
           TRACE: ${{ secrets.ACTIONS_STEP_DEBUG || 'false' }}
-          GEM_TOKEN: ${{ secrets[matrix.registry.secret] }}
           REGISTRY: ${{ matrix.registry.key }}
+          GEM_TOKEN: ${{ matrix.registry.key == 'rubygems' && secrets.RUBYGEMS_TOKEN || matrix.registry.key == 'github' && secrets.GEM_TOKEN_GITHUB }}
         run: |
EOF
@@ -30,4 +30,4 @@
TRACE: ${{ secrets.ACTIONS_STEP_DEBUG || 'false' }}
GEM_TOKEN: ${{ secrets[matrix.registry.secret] }}
REGISTRY: ${{ matrix.registry.key }}
GEM_TOKEN: ${{ matrix.registry.key == 'rubygems' && secrets.RUBYGEMS_TOKEN || matrix.registry.key == 'github' && secrets.GEM_TOKEN_GITHUB }}
run: |
Copilot is powered by AI and may make mistakes. Always verify output.
REGISTRY: ${{ matrix.registry.key }}
run: |
bundle install
TRACE="$TRACE" GEM_TOKEN="$GEM_TOKEN" ./ci/publish-gem.sh "$REGISTRY"
shell: bash
Comment on lines +8 to +36

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
6 changes: 2 additions & 4 deletions .github/workflows/main.yml → .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: Ruby

on:
push:
branches:
- main
workflow_call:

pull_request:
workflow_dispatch:

jobs:
build:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Publish

on: # yamllint disable-line rule:truthy
workflow_dispatch:
workflow_call:

jobs:
gem:
name: Build and publish gem
uses: ./.github/workflows/gem.yaml
secrets: inherit

containers:
Comment on lines +10 to +14

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
name: Build and publish OCI container images
uses: ./.github/workflows/container.yaml
secrets: inherit
Comment on lines +15 to +17

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
51 changes: 51 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: Release

on: # yamllint disable-line rule:truthy
push:
branches:
- main
workflow_dispatch:
workflow_call:

jobs:
validate:
name: Validations
uses: ./.github/workflows/validations.yaml

release:
needs: [validate]
name: Create a release
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
-
uses: actions/checkout@v4
id: git-checkout
with:
fetch-tags: true
-
uses: googleapis/release-please-action@v4
id: release
with:
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
-
id: debug
env:
RELEASE_CREATED: ${{ steps.release.outputs.release_created }}
TRACE: ${{ secrets.ACTIONS_STEP_DEBUG || 'false' }}
run: |
if [ "$TRACE" != 'false' ]
then
printf 'Release created: %s\n' "$RELEASE_CREATED"
fi

publish:
if: needs.release.outputs.release_created
needs: release
name: Build and publish artifacts
uses: ./.github/workflows/publish.yaml
secrets: inherit
12 changes: 12 additions & 0 deletions .github/workflows/validations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Validations

on: # yamllint disable-line rule:truthy
workflow_dispatch:
workflow_call:
pull_request:

jobs:
validate_ruby:
name: Ruby Tests
uses: ./.github/workflows/main.yaml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/tmp/
Gemfile.lock
*.swp
*.gem
32 changes: 32 additions & 0 deletions .release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"packages": {
".": {
"changelog-path": "CHANGELOG.md",
"release-type": "simple",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"draft": false,
"prerelease": false,
"version-file": ".version.txt",
"extra-files": [
{
"type": "generic",
"path": "lib/sequel/pgt_outbox/version.rb"
},
{
"type": "generic",
"path": "oci/Gemfile"
}
],
"exclude-paths": [
".release-please-manifest.json",
".version.txt",
"lib/sequel/pgt_outbox/version.rb",
".rubocop.yml",
".overcommit.yml",
"coverage/coverage.json"
]
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.2.0"
}
1 change: 1 addition & 0 deletions .version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2.0
43 changes: 0 additions & 43 deletions README.md

This file was deleted.

16 changes: 16 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@ task :spec do
sh 'bundle exec ./test/sequel/test_pgt_outbox.rb'
end

desc 'Create the test database'
task :createdb do
require 'uri'
uri = URI.parse(ENV.fetch('PGT_SPEC_DB', 'postgres:///spgt_test'))
sh "createdb '#{File.basename(uri.path)}'"
end

desc 'Drop the test database'
task :dropdb do
require 'uri'
uri = URI.parse(ENV.fetch('PGT_SPEC_DB', 'postgres:///spgt_test'))
sh "dropdb --if-exists '#{File.basename(uri.path)}'"
end

task resetdb: %i[dropdb createdb]

task default: %i[rubocop spec]
Loading
Loading