Skip to content

Commit

Permalink
Use central prod token for project api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gayaldassanayake committed Aug 27, 2024
1 parent 980d189 commit 1cf136d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/daily-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ jobs:
packageUser: ${{ github.actor }}
packagePAT: ${{ secrets.GITHUB_TOKEN }}
devCentralToken: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }}
prodCentralToken: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }}
ballerinaBotWorkflow: $ {{ secrets.BALLERINA_BOT_WORKFLOW }}
TEST_MODE_ACTIVE: true
run: ./gradlew :project-api-tests:test --stacktrace --scan --console=plain --no-daemon --continue
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
devCentralToken: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }}
prodCentralToken: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }}
ballerinaBotWorkflow: $ {{ secrets.BALLERINA_BOT_WORKFLOW }}
run: |
./gradlew build -Pversion=${VERSION}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.Map;
import java.util.Objects;

import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_DEV_CENTRAL;
import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_HOME_DIR;
import static org.ballerina.projectapi.CentralTestUtils.TEST_MODE_ACTIVE;
import static org.ballerina.projectapi.CentralTestUtils.createSettingToml;
import static org.ballerina.projectapi.CentralTestUtils.deleteFiles;
import static org.ballerina.projectapi.CentralTestUtils.getEnvVariables;
Expand Down Expand Up @@ -89,7 +89,7 @@ public void testCodeGenOfflineResolution() throws IOException, InterruptedExcept
*/
private Map<String, String> addEnvVariables(Map<String, String> envVariables) {
envVariables.put(BALLERINA_HOME_DIR, tempHome.toString());
envVariables.put(BALLERINA_DEV_CENTRAL, "true");
envVariables.put(TEST_MODE_ACTIVE, "true");
return envVariables;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private CentralTestUtils() {

static final String BALLERINA_HOME_DIR = "BALLERINA_HOME_DIR";
static final String BALLERINA_DEV_CENTRAL = "BALLERINA_DEV_CENTRAL";
static final String TEST_MODE_ACTIVE = "TEST_MODE_ACTIVE";
static final String BALLERINA_CENTRAL_ACCESS_TOKEN = "BALLERINA_CENTRAL_ACCESS_TOKEN";
static final String BALLERINA_TOML = "Ballerina.toml";
static final String DEPENDENCIES_TOML = "Dependencies.toml";
Expand Down Expand Up @@ -96,21 +97,30 @@ static String randomPackageName(int count) {
* @throws IOException i/o exception when writing to file
*/
static void createSettingToml(Path dirPath) throws IOException {
String content = "[central]\n accesstoken = \"" + getToken() + "\"";
String content = "[central]\n accesstoken = \"" + getProdToken() + "\"";
Files.write(dirPath.resolve("Settings.toml"), content.getBytes(), StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
}

/**
* Get token of ballerina-central-bot required to push the module.
* Get token of ballerina-dev-central required to push the module.
*
* @return token required to push the module.
*/
private static String getToken() {
private static String getDevToken() {
// staging and dev both has the same access token
return System.getenv("devCentralToken");
}

/**
* Get token of ballerina-central required to push the module.
*
* @return token required to push the module.
*/
private static String getProdToken() {
return System.getenv("prodCentralToken");
}

/**
* Get token of ballerina-bot required to dispatch GitHub workflows.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import java.util.List;
import java.util.Map;

import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_DEV_CENTRAL;
import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_HOME_DIR;
import static org.ballerina.projectapi.CentralTestUtils.TEST_MODE_ACTIVE;

/**
* Utility class for tests.
Expand Down Expand Up @@ -146,7 +146,7 @@ public static void cleanDistribution() throws IOException {
*/
static Map<String, String> addEnvVariables(Map<String, String> envVariables, Path tempHomeDirectory) {
envVariables.put(BALLERINA_HOME_DIR, tempHomeDirectory.toString());
envVariables.put(BALLERINA_DEV_CENTRAL, "true");
envVariables.put(TEST_MODE_ACTIVE, "true");
return envVariables;
}
}

0 comments on commit 1cf136d

Please sign in to comment.