Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add games.json and script to create and update branches #152

Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
bf6719f
Feature: Add `games.json` and script to create / update branches for v2
leojonathanoh Sep 15, 2023
0cc2644
Update `.gitlab-ci.yml` and use it in branches
leojonathanoh Sep 16, 2023
bb27af1
Add missing `$LASTEXITCODE`
leojonathanoh Sep 16, 2023
e7cbad7
Improve logging and add test
leojonathanoh Sep 16, 2023
84cd75c
Fix removing of files before checking out
leojonathanoh Sep 16, 2023
187223f
Add `test-generate-gitbranches` job
leojonathanoh Sep 16, 2023
b5a1c1b
Fix
leojonathanoh Sep 16, 2023
37fed67
Use -Pull in tests
leojonathanoh Sep 16, 2023
3b6287d
Fix -Pull
leojonathanoh Sep 16, 2023
483f85e
Reset branch to remote branch only if remote branch exists when using…
leojonathanoh Sep 16, 2023
2280a99
Get Pester version at beginning of test
leojonathanoh Sep 16, 2023
0f252f2
Preserve `.trigger`
leojonathanoh Sep 16, 2023
48c17c3
Add support for updating existing `.env` and `.state`
leojonathanoh Sep 16, 2023
a55ca1e
Cleanup and add examples
leojonathanoh Sep 16, 2023
df7fdcd
Remove `ConvertFrom-Json -Depth`
leojonathanoh Sep 16, 2023
d67982b
Improve script param comments
leojonathanoh Sep 16, 2023
2a08892
Add `-Push`
leojonathanoh Sep 16, 2023
b1cad71
Use CmdletBinding and parameter validation
leojonathanoh Sep 16, 2023
ba8eb59
Update `games.json`
leojonathanoh Sep 27, 2023
70a390e
Update docker image in `.gitlab-ci.yml`
leojonathanoh Sep 27, 2023
a98f4c2
Add ability to populate a brand new repo
leojonathanoh Sep 27, 2023
32415da
Refactor: Simplify param
leojonathanoh Sep 27, 2023
20f0952
Throw error message if script is not in a git repository
leojonathanoh Sep 27, 2023
3ca5b81
Improve error message if `-TargetRepo` does not have a 'master' branch
leojonathanoh Sep 27, 2023
52be4c6
Update examples
leojonathanoh Sep 27, 2023
ba10c3e
Fix
leojonathanoh Sep 27, 2023
0fd720b
Fix logging
leojonathanoh Sep 27, 2023
8afbf53
Fix
leojonathanoh Sep 27, 2023
bb90101
Use -TargetRepo . for same repo test
leojonathanoh Sep 27, 2023
6ebd1b2
Fix examples
leojonathanoh Sep 27, 2023
7031e11
Add `NO_PUSH` and `NO_PULL` in `.env`
leojonathanoh Sep 27, 2023
525b4dc
Add dry run support
leojonathanoh Sep 27, 2023
abd3b4d
Always checkout to 'master'
leojonathanoh Sep 27, 2023
0d093cf
Improve comments
leojonathanoh Sep 27, 2023
93a0a5e
Improve test
leojonathanoh Sep 27, 2023
7b79e39
Checkout back to original ref at end of script if -TargetRepo is the …
leojonathanoh Sep 27, 2023
515c220
Add REGISTRY_* and STEAM_* variables
leojonathanoh Oct 21, 2023
0c1f704
Add `CACHE` and `NO_PULL` env vars
leojonathanoh Oct 21, 2023
99fafb9
Update games.json
leojonathanoh Nov 21, 2023
bcba6cf
Check that `master` has an initial commit
leojonathanoh Nov 22, 2023
d586dc5
Revert "Check that `master` has an initial commit"
leojonathanoh Nov 22, 2023
a6113fd
Add `NO_CACHE`
leojonathanoh Nov 27, 2023
f08e59d
Add message about using `git init -b master` if `-TargetRepo` is not …
leojonathanoh Nov 27, 2023
4b69f4b
Rename `-TargetRepo` to `-Repo`
leojonathanoh Nov 27, 2023
107b389
Use string array for `-GamePlatform`, `-GameEngine`, and `-Game` to a…
leojonathanoh Nov 27, 2023
6bb2002
Add test for `-GamePlatform`, `-GameEngine` and `-Game`
leojonathanoh Nov 27, 2023
ad46d3b
Test `-Pull` only on one test to speed up tests
leojonathanoh Nov 27, 2023
4b99b71
Show command to create a new repo
leojonathanoh Nov 27, 2023
ddb198e
Use comment-based help
leojonathanoh Nov 27, 2023
0985f84
Add HelpMessage
leojonathanoh Nov 27, 2023
783b5ac
Rearrange `NO_CACHE`
leojonathanoh Dec 5, 2023
86e2030
Update `games.json`
leojonathanoh Dec 5, 2023
b9fdb59
Breaking: Update notify.sh to v2
leojonathanoh Sep 15, 2023
6b9d607
Update to latest
leojonathanoh Nov 22, 2023
0878306
Update games.json
leojonathanoh Dec 7, 2023
b5ade7d
Update games.json
leojonathanoh Dec 7, 2023
59e4b7a
Update games.json
leojonathanoh Dec 7, 2023
58dd1ec
Add `-Remote`
leojonathanoh Dec 8, 2023
c2f2ed1
Use `git ls-files` to remove files
leojonathanoh Dec 8, 2023
69acb30
Add `.gitignore`
leojonathanoh Dec 8, 2023
060a0c4
`git add` only needed files
leojonathanoh Dec 8, 2023
65d2ce1
Revert "`git add` only needed files"
leojonathanoh Dec 8, 2023
20c25a9
Create `.gitignore`
leojonathanoh Dec 8, 2023
03eb98b
Remove `GAME_PLATFORM` and `GAME_ENGINE` from `.env`
leojonathanoh Dec 8, 2023
a7b8d61
Set `FIX_APPMANIFEST` to false in `games.json`
leojonathanoh Dec 8, 2023
f077d78
Leave `FIX_APPMANIFEST` empty in `.env`
leojonathanoh Dec 8, 2023
c6ce4fc
Update `games.json`
leojonathanoh Dec 8, 2023
a1fd50c
Update `games.json`
leojonathanoh Dec 8, 2023
2694e37
Remove `Generate-games.json.ps1`
leojonathanoh Dec 8, 2023
065ced0
Remove unneeded `CI_JOB_ID`
leojonathanoh Dec 8, 2023
60299ae
Update build status badges
joeltimothyoh Dec 8, 2023
ce1a270
Update `games.json`
leojonathanoh Dec 9, 2023
383e955
`.gitignore` all files except those needed
leojonathanoh Dec 9, 2023
3198dfc
Update `README.md`
joeltimothyoh Dec 9, 2023
f6de128
Update `.gitignore` for game branches
joeltimothyoh Dec 9, 2023
89f1321
Checkout files from source ref
leojonathanoh Dec 9, 2023
e4116d2
Enable `services` key in `.gitlab-ci.yml`
leojonathanoh Dec 9, 2023
2117782
Fix comment
leojonathanoh Dec 9, 2023
049ddb1
Display `DOCKER_*` env vars at start of script
leojonathanoh Dec 9, 2023
086fab8
Fix displaying `DOCKER_*` env vars
leojonathanoh Dec 9, 2023
9131164
Change to `PIPELINE=update`
leojonathanoh Dec 9, 2023
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
34 changes: 8 additions & 26 deletions .generate/Generate-GameImageRepositoryReadme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,41 +98,23 @@ $gameList | % {

# Generate game image repository readme content
$content = @"
| ``master`` | ``build`` | ``update`` |
|:-:|:-:|:-:|
[![pipeline-github-master-badge][]][pipeline-github-master-link] | [![pipeline-travis-build-badge][]][pipeline-travis-build-link] [![pipeline-azurepipelines-build-badge][]][pipeline-azurepipelines-build-link] [![pipeline-circleci-build-badge][]][pipeline-circleci-build-link] [![pipeline-gitlab-build-badge][]][pipeline-gitlab-build-link] | [![pipeline-travis-update-badge][]][pipeline-travis-update-link] [![pipeline-azurepipelines-update-badge][]][pipeline-azurepipelines-update-link] [![pipeline-circleci-update-badge][]][pipeline-circleci-update-link] [![pipeline-gitlab-update-badge][]][pipeline-gitlab-update-link]
| ``master`` |
|:-:|
[![pipeline-github-master-badge][]][pipeline-github-master-link] |

[pipeline-github-master-badge]: https://img.shields.io/github/actions/workflow/status/startersclan/docker-sourceservers/ci-master-pr.yml?branch=master&label=&logo=github&style=flat-square
[pipeline-github-master-link]: https://github.com/startersclan/docker-sourceservers/actions?query=branch%3Amaster

[pipeline-travis-build-badge]: https://img.shields.io/travis/com/startersclan/docker-sourceservers/build.svg?label=&logo=travis&style=flat-square
[pipeline-travis-build-link]: https://app.travis-ci.com/startersclan/docker-sourceservers/builds
[pipeline-travis-update-badge]: https://img.shields.io/travis/com/startersclan/docker-sourceservers/update.svg?label=&logo=travis&style=flat-square
[pipeline-travis-update-link]: https://app.travis-ci.com/startersclan/docker-sourceservers/builds

[pipeline-azurepipelines-build-badge]: https://img.shields.io/azure-devops/build/startersclan/docker-sourceservers/2/build.svg?label=&logo=azure-pipelines&style=flat-square
[pipeline-azurepipelines-build-link]: https://dev.azure.com/startersclan/docker-sourceservers/_build?definitionId=2
[pipeline-azurepipelines-update-badge]: https://img.shields.io/azure-devops/build/startersclan/docker-sourceservers/3/update.svg?label=&logo=azure-pipelines&style=flat-square
[pipeline-azurepipelines-update-link]: https://dev.azure.com/startersclan/docker-sourceservers/_build?definitionId=3

[pipeline-circleci-build-badge]: https://img.shields.io/circleci/build/gh/startersclan/docker-sourceservers/build.svg?label=&logo=circleci&style=flat-square
[pipeline-circleci-build-link]: https://app.circleci.com/pipelines/github/startersclan/docker-sourceservers?branch=build
[pipeline-circleci-update-badge]: https://img.shields.io/circleci/build/gh/startersclan/docker-sourceservers/update.svg?label=&logo=circleci&style=flat-square
[pipeline-circleci-update-link]: https://app.circleci.com/pipelines/github/startersclan/docker-sourceservers?branch=update

[pipeline-gitlab-build-badge]: https://img.shields.io/gitlab/pipeline-status/startersclan/docker-sourceservers?branch=build&label=&logo=gitlab&style=flat-square
[pipeline-gitlab-build-link]: https://gitlab.com/startersclan/docker-sourceservers/-/pipelines?page=1&scope=all&ref=build
[pipeline-gitlab-update-badge]: https://img.shields.io/gitlab/pipeline-status/startersclan/docker-sourceservers?branch=update&label=&logo=gitlab&style=flat-square
[pipeline-gitlab-update-link]: https://gitlab.com/startersclan/docker-sourceservers/-/pipelines?page=1&scope=all&ref=update

| Game | Image | Tag ``v<tag>`` | Size |
|:-:|:-:|:-:|:-:|
| $($_.FullName) | [``$RegistryNamespace/$($_.Name)``][$engine-$($_.Name)-dockerhub-link] | [![$engine-$($_.Name)-version-badge][]][$engine-$($_.Name)-metadata-link] | [![$engine-$($_.Name)-size-badge][]][$engine-$($_.Name)-metadata-link] | [![$engine-$($_.Name)-layers-badge][]][$engine-$($_.Name)-metadata-link] |
| Game | Image | Tag ``v<tag>`` | Size | Status |
|:-:|:-:|:-:|:-:|:-:|
| $($_.FullName) | [``$RegistryNamespace/$($_.Name)``][$engine-$($_.Name)-dockerhub-link] | [![$engine-$($_.Name)-version-badge][]][$engine-$($_.Name)-metadata-link] | [![$engine-$($_.Name)-size-badge][]][$engine-$($_.Name)-metadata-link] | [![pipeline-gitlab-$engine-$($_.Name)-badge][]][pipeline-gitlab-$engine-$($_.Name)-link] |

[$engine-$($_.Name)-dockerhub-link]: https://hub.docker.com/r/$RegistryNamespace/$($_.Name)
[$engine-$($_.Name)-version-badge]: https://img.shields.io/docker/v/$RegistryNamespace/$($_.Name)/latest?label=&style=flat-square
[$engine-$($_.Name)-size-badge]: https://img.shields.io/docker/image-size/$RegistryNamespace/$($_.Name)/latest?label=&style=flat-square
[$engine-$($_.Name)-metadata-link]: https://hub.docker.com/r/$RegistryNamespace/$($_.Name)/tags
[pipeline-gitlab-$engine-$($_.Name)-badge]: https://img.shields.io/gitlab/pipeline-status/startersclan/docker-sourceservers?branch=$engine-$($_.Name)&label=&logo=gitlab&style=flat-square
[pipeline-gitlab-$engine-$($_.Name)-link]: https://gitlab.com/startersclan/docker-sourceservers/-/pipelines?page=1&scope=all&ref=$engine-$($_.Name)
"@
$content
$outFile = "$readmePath/$engine-$($_.Name).md"
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ jobs:
run: |
./test/test-game-image-game-version.sh

test-generate-gitbranches:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all branches and tags
- name: Test
shell: pwsh
run: |
./Generate-GitBranches.Tests.ps1

update-draft-release:
needs:
- test-build-hlds
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.*
!/.circleci
!/.github
!/.generate
!/.gitignore
!/.gitlab-ci.yml
!/.travis.yml
35 changes: 19 additions & 16 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
stages:
- build
- post-build
- notify

build-image:
stage: build
image: docker:20.10.18-git
image: docker:20.10.23-git
# See: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker
# For stateless builds, a sidecar dockerd service is needed
# For stateful builds (i.e. DOCKER_HOST=unix:///var/run/docker.sock mounted from the host), a sidecar dockerd service is not needed
# services:
# - docker:20.10.18-dind
rules:
- if: $CI_PIPELINE_SOURCE == "trigger"
- if: $CI_PIPELINE_SOURCE == "web"
# - docker:20.10.23-dind
variables:
DOCKER_DRIVER: overlay2
rules:
# Run on all branches except master, when .trigger is added or modified
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH != "master"
changes:
- .trigger
timeout: 120m
script:
- |
export PIPELINE="$CI_COMMIT_BRANCH"
set +e
./build.sh
if [ $? = 0 ]; then
Expand All @@ -28,20 +29,22 @@ build-image:
exit 1
fi
artifacts:
name: .build.state-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
paths:
- .build.state
when: always
expire_in: never

send-notification:
stage: post-build
image: alpine:3.14.8
notify:
stage: notify
image: alpine:3.15
rules:
- if: $CI_PIPELINE_SOURCE == "trigger"
- if: $CI_PIPELINE_SOURCE == "web"
# Run on all branches except master, when .trigger is added or modified
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH != "master"
changes:
- .trigger
when: always
timeout: 5m
script:
- |
apk add --no-cache curl
export X_CI_WEBHOOK_SECRET_HEADER="x-gitlab-webhook-secret: $X_GITLAB_WEBHOOK_SECRET"
./notify.sh
- apk add --no-cache curl
- ./notify.sh
142 changes: 142 additions & 0 deletions Generate-GitBranches.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
Get-Module Pester -ListAvailable

Describe "Generate-GitBranches.ps1" {

BeforeEach {
$testDrive = "TestDrive:"
$sourceRepo = $PSScriptRoot

$games = Get-Content $PSScriptRoot/games.json -Encoding utf8 | ConvertFrom-Json -AsHashtable
$remote = 'origin'
$remoteUrl = git remote get-url $

$expectedFiles = @(
'.env'
'.gitignore'
'.gitlab-ci.yml'
'.state'
'build.sh'
'build/Dockerfile'
'notify.sh'
'update/Dockerfile'
)
}

AfterEach {
cd $sourceRepo
Remove-Item $testDrive/* -Recurse -Force
}

It "Parameter validation" {
{
cd $PSScriptRoot
& ./Generate-GitBranches.ps1 -Repo '' -ErrorAction Stop
} | Should -Throw
}

Context 'Same repo' {

BeforeEach {
$sameRepo = "$testDrive/$( (Get-Item $sourceRepo).Name )"
Copy-Item $sourceRepo $sameRepo -Recurse -Force
cd $sameRepo
git config user.name "bot"
git config user.email "bot@example.com"
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
foreach ($b in $branches) {
git branch -D $b
}
}

It "Creates and updates branches of a same repo (dry-run)" {
$currentRef = git rev-parse --short HEAD
if ($LASTEXITCODE) { throw }
& ./Generate-GitBranches.ps1 -Repo . -ErrorAction Stop -WhatIf 6>$null # Create
git checkout $currentRef
& ./Generate-GitBranches.ps1 -Repo . -ErrorAction Stop -WhatIf 6>$null # Update

cd $sameRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 0
}

It "Creates and updates branches of a same repo" {
$currentRef = git rev-parse --short HEAD
if ($LASTEXITCODE) { throw }
& ./Generate-GitBranches.ps1 -Repo $sameRepo -ErrorAction Stop 6>$null # Create
git checkout $currentRef
& ./Generate-GitBranches.ps1 -Repo $sameRepo -ErrorAction Stop 6>$null # Update

cd $sameRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be $games.Count
foreach ($b in $branches) {
git ls-tree -r --name-only $b | Should -Be $expectedFiles
}
}

It "Creates and updates branches of a same repo of (one game)" {
& $sourceRepo/Generate-GitBranches.ps1 -Repo $sameRepo -GamePlatform steam -GameEngine hlds -Game valve -ErrorAction Stop 6>$null # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $sameRepo -Remote $remote -Pull -GamePlatform steam -GameEngine hlds -Game valve -ErrorAction Stop 6>$null # Update

cd $sameRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 1
foreach ($b in $branches) {
git ls-tree -r --name-only $b | Should -Be $expectedFiles
}
}
}

Context 'Different repo' {

BeforeEach {
$differentRepo = "$testDrive/$( (Get-Item $sourceRepo).Name )"
New-Item $differentRepo -ItemType Directory > $null
cd $differentRepo
git init --initial-branch master
git config user.name "bot"
git config user.email "bot@example.com"
git commit --allow-empty -m 'Init'
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
foreach ($b in $branches) {
git branch -D $b
}
}

It "Creates and updates branches of a different repo (dry-run)" {
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null -WhatIf # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null -WhatIf # Update

cd $differentRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 0
}

It "Creates and updates branches of a different repo" {
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null # Update

cd $differentRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be $games.Count
foreach ($b in $branches) {
git ls-tree -r --name-only $b | Should -Be $expectedFiles
}
}

It "Creates and updates branches of a different repo (one game)" {
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -GamePlatform steam -GameEngine hlds -Game valve -ErrorAction Stop 6>$null # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -GamePlatform steam -GameEngine hlds -Game valve -ErrorAction Stop 6>$null # Update

cd $differentRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 1
foreach ($b in $branches) {
git ls-tree -r --name-only $b | Should -Be $expectedFiles
}
}

}

}
Loading