Skip to content

Commit

Permalink
Upload not working properly (#1) (#2)
Browse files Browse the repository at this point in the history
Fixed the not properly working upload by fixing the API error within the
implementation. We falsely used the same API for groups and projects,
which is of course wrong.
Furthermore for uploading we should be only allowed to use the projects
endpoint. Besides those improvements we also added better logging and
extracted some logic.
  • Loading branch information
aepfli authored Mar 8, 2021
1 parent f74b506 commit bf1ba58
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 115 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ jobs:

- name: Build
uses: eskatos/[email protected]
with:
arguments: build
env:
TEST_UPLOAD_TOKEN: ${{secrets.TEST_UPLOAD_TOKEN}}
with:
arguments: build -i
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,28 @@ apply(plugin = "at.schrottner.gitlab-repositories")
The plugin offers you a nice helper method inspired by `gradle-jruby-plugin` to easily add repositories.

```groovy
gitLab.maven(projectOrGroupId)
gitLab.maven(projectOrGroupId) {
gitLab.project(projectId)
gitLab.project(projectId) {
name = "custom name"
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
}
gitLab.group(groupId)
gitLab.group(groupId) {
name = "custom name"
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
}
```

For adding a repository to the maven-publish repositories please use following method. The `owner` needs to be provided
and is a reference to the `repositories`.
and is a reference to the `repositories`. Be aware that this has to be a groupId

```groovy
publishing {
repositories {
gitLab.upload(owner, projectOrGroupId)
gitLab.upload(owner, projectOrGroupId) {
gitLab.upload(owner, projectId)
gitLab.upload(owner, projectId) {
name = "custom name"
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
Expand All @@ -159,23 +165,28 @@ publishing {
This will add a repository and will apply conditions for the first token matching, and not being empty.

```groovy
gitLab.maven(1)
gitLab.project(1)
gitLab.group(1)
```

### Adding a repository with specific tokens

We can define which tokens should be taken into account (currently order of parameter is ignored)

```groovy
gitLab.maven(1) {
gitLab.project(1) {
tokenSelectors = ['private', 'deploy']
}
gitLab.group(1) {
tokenSelectors = ['private', 'deploy']
}
```

Additionally, we can provide one specific token to be used, if the token is not set, or empty, nothing will be done.

```groovy
gitLab.maven(1) { tokenSelector = 'deploy' }
gitLab.project(1) { tokenSelector = 'deploy' }
gitLab.group(1) { tokenSelector = 'deploy' }
```

## Comparison
Expand All @@ -202,7 +213,7 @@ gitLab {
}
repositories {
gitLab.maven("ID")
gitLab.group("ID")
}
publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ import org.gradle.testkit.runner.GradleRunner
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import java.nio.file.Files

import static org.assertj.core.api.Assertions.assertThat

class GitlabRepositoriesPluginFunctionalTests {

private static final Logger logger = LoggerFactory.getLogger(GitlabRepositoriesPluginFunctionalTests.class)
private pluginClasspath = getClass().classLoader.findResource("plugin-classpath.txt")
.readLines()
.collect { it.replace('\\\\', '\\\\\\\\') } // escape backslashes in Windows paths
Expand Down Expand Up @@ -103,7 +109,28 @@ class GitlabRepositoriesPluginFunctionalTests {

@Test
void "used in settings and project"() {

if (!System.getenv('TEST_UPLOAD_TOKEN')) {

logger.warn """
##########################################################
##########################################################
##########################################################
##########################################################
This tests runs without an attempt of uploading
Please configure a TEST_UPLOAD_TOKEN which has
upload rights.
##########################################################
##########################################################
##########################################################
##########################################################
"""
}
//given:
def file = new File(getClass().getResource('/test.xml').toURI())

Files.copy(file.toPath(), projectDir.toPath().resolve(file.name))

settingsGradle << """
$apply
gitLab {
Expand All @@ -124,6 +151,10 @@ class GitlabRepositoriesPluginFunctionalTests {
apply plugin: at.schrottner.gradle.GitlabRepositoriesPlugin
gitLab {
${generateToken('PrivateToken', 'PrivateToken')}
token(PrivateToken) {
it.key = 'testToken'
it.value = '${System.getenv('TEST_UPLOAD_TOKEN')}'
}
}
publishing {
repositories {
Expand All @@ -132,9 +163,9 @@ class GitlabRepositoriesPluginFunctionalTests {
name = "NotAdded"
tokenSelector = "jobToken"
}
gitLab.upload(owner, "testAdded") {
gitLab.upload(owner, "24974077") {
name = "GitLab"
tokenSelector = "token1"
tokenSelector = "testToken"
}
gitLab.upload(owner, "testAdded") {
name = "GitLabSettingsToken"
Expand All @@ -144,10 +175,24 @@ class GitlabRepositoriesPluginFunctionalTests {
name = "GitLabAnyToken"
}
}
publications {
test(MavenPublication) {
artifactId 'test-file'
groupId 'at.schrottner.test.gitlab-repositories'
version 'test-SNAPSHOT'
artifact source: 'test.xml', classifier: 'features'
}
}
}
"""
//when:
BuildResult result = runTest()
def runner = GradleRunner.create()
runner.forwardOutput()
runner.withPluginClasspath()
runner.withArguments("tasks", "-i", "-s")
runner.withProjectDir(projectDir)
def result = runner.build()

//then:
assertThat(result.output)
Expand All @@ -160,12 +205,23 @@ class GitlabRepositoriesPluginFunctionalTests {
"Settings evaluated",
"replaced Job-Token: jobToken",
"replaced Private-Token: token0",
"replaced Private-Token: token1"
"replaced Private-Token: token1",
"added Private-Token: testToken"
)
.contains("publishAllPublicationsToGitLabSettingsTokenRepository")
.contains("publishAllPublicationsToGitLabAnyTokenRepository")
.contains("publishAllPublicationsToGitLabRepository")
.contains("Maven Repository NotAdded was not added, as no token could be applied!\n")

if (System.getenv('TEST_UPLOAD_TOKEN')) {
def uploadRunner = GradleRunner.create()
uploadRunner.forwardOutput()
uploadRunner.withPluginClasspath()
uploadRunner.withArguments("publishTestPublicationToGitLabRepository", "-i", "-s")
uploadRunner.withProjectDir(projectDir)
def uploadResult = uploadRunner.build()
assertThat(uploadResult.output).contains("Publishing to repository 'GitLab'")
}
}

def getApply() {
Expand Down
2 changes: 2 additions & 0 deletions src/functionalTest/resources/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" ?>
<tests/>
Loading

0 comments on commit bf1ba58

Please sign in to comment.