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 21, 2024
1 parent ae6772e commit a9e2fba
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/daily-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ jobs:
packageUser: ${{ github.actor }}
packagePAT: ${{ secrets.GITHUB_TOKEN }}
devCentralToken: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }}
prodCentralToken: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }}
githubAccessToken: ${{ secrets.GITHUB_TOKEN }}
ballerinaBotWorkflow: $ {{ secrets.BALLERINA_BOT_WORKFLOW }}
TEST_MODE_ACTIVE: true
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 }}
githubAccessToken: ${{ secrets.GITHUB_TOKEN }}
ballerinaBotWorkflow: $ {{ secrets.BALLERINA_BOT_WORKFLOW }}
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
import static io.ballerina.projects.util.ProjectConstants.BALA_DIR_NAME;
import static io.ballerina.projects.util.ProjectConstants.CENTRAL_REPOSITORY_CACHE_NAME;
import static io.ballerina.projects.util.ProjectConstants.REPOSITORIES_DIR;
import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_DEV_CENTRAL;
import static org.ballerina.projectapi.CentralTestUtils.OUTPUT_NOT_CONTAINS_EXP_MSG;
import static org.ballerina.projectapi.CentralTestUtils.TEST_MODE_ACTIVE;
import static org.ballerina.projectapi.CentralTestUtils.createSettingToml;
import static org.ballerina.projectapi.CentralTestUtils.getEnvVariables;
import static org.ballerina.projectapi.CentralTestUtils.getString;
import static org.ballerina.projectapi.CentralTestUtils.isToolAvailableInCentral;
Expand All @@ -56,6 +57,7 @@

public class BalToolTest {
private Path tempWorkspaceDirectory;
private Path tempHomeDirectory;
private final String orgName = "bctestorg";
private static final String toolId = "disttest";
private static final String nonExistingTool = "disttest2";
Expand All @@ -75,10 +77,12 @@ public class BalToolTest {
@BeforeClass()
public void setUp() throws IOException, InterruptedException {
TestUtils.setupDistributions();
tempHomeDirectory = Files.createTempDirectory("bal-test-integration-packaging-home-");
tempWorkspaceDirectory = Files.createTempDirectory("bal-test-integration-packaging-workspace-");
createSettingToml(tempHomeDirectory);
setToolEnvironmentsForSubCommands();
Map<String, String> envVariables = getEnvVariables();
envVariables.put(BALLERINA_DEV_CENTRAL, "true");
envVariables.put(TEST_MODE_ACTIVE, "true");
if (!isToolAvailableInCentral(toolId, tempWorkspaceDirectory, envVariables)) {
Assert.fail("Tool " + toolId + " is not available in central");
}
Expand Down Expand Up @@ -994,7 +998,6 @@ private Pair<String, String> executeHelpFlagOfTool(String toolId, Map<String, St
}

private ToolEnvironment getToolEnvironment(ToolSubCommand subCommand) throws IOException {
Path tempHomeDirectory = Files.createTempDirectory("bal-test-integration-packaging-home-");
Map<String, String> envVariables = TestUtils.addEnvVariables(getEnvVariables(),
tempHomeDirectory);
Path balToolsTomlPath = tempHomeDirectory.resolve(".config").resolve("bal-tools.toml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,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 @@ -107,7 +107,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 @@ -59,6 +59,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 @@ -97,21 +98,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 @@ -156,7 +156,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 a9e2fba

Please sign in to comment.