Last week I got hit by a headache - our perfectly tuned Lingo.dev GitHub Actions workflow couldn't run on a contributor's GitLab instance. Then I realized I’d actually like to run the same automation everywhere, regardless of the platform.
So I went on a quest to build a cross-platform CI automation that runs on GitHub, GitLab, and Bitbucket (and possibly others too!). The solution started as a simple GitHub Action but evolved into something more powerful when we needed to support multiple code hosting platforms.
I will walk you through the exact process:
- starting simple, I will showcase how Github Actions work
- leveling up to build reusable Docker image
- finally I will show you how to run this on each platform
Follow the steps to build and ship your first cross-platform action. Or bookmark the article for later.
tl;dr see the template repository ???
1. Starting Simple: Run JavaScript in GitHub Actions
Running a GitHub Action
Let's start with the simplest possible GitHub Action - one that runs a JavaScript file. First, create index.js in the root of your repository:
console.log("Hello World");
Now create a workflow file .github/workflows/hello.yml:
name: Hello World on: push: branches: - main jobs: hello: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: "20" - name: Say Hello run: node index.js
This action will:
- Trigger on push to main branch
- Check out your repository
- Set up Node.js environment
- Run your script
Making it Reusable
Now, let's make this action reusable by moving it to a separate repository. Create a new GitHub repository (e.g., hello-world-action like my example here) with these files:
- index.js (same as before):
console.log("Hello World");
- action.yml:
name: "Hello World Action" description: "A simple action that says hello" runs: using: "node20" main: "index.js"
Now you can use this action in any repository by referencing it in your workflow:
name: Use Hello Action on: push: branches: - main jobs: hello: runs-on: ubuntu-latest steps: - name: Say Hello uses: your-username/hello-world-action@main
The key differences are:
- The action lives in its own repository
- action.yml defines how to run the action
- Other repositories can reference it using uses: your-username/hello-world-action@ref
2. Leveling Up: Dockerized TypeScript Action
Now, let's create a more sophisticated action that runs TypeScript code. We'll need several files:
-
Initialize the project and set up TypeScript:
pnpm init # Creates package.json pnpm add -D typescript # Install TypeScript as dev dependency
-
Update your package.json to add the build script:
{ "scripts": { "build": "tsc" } }
Then rename our index.js to index.ts to use TypeScript instead of JavaScript and move it to the src directory.
-
Create tsconfig.json to configure TypeScript compilation:
{ "compilerOptions": { "target": "ES2022", "module": "commonjs", "outDir": "./build", "rootDir": "./src", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, "exclude": ["node_modules", "build", "**/*.test.ts"] }
Create a Dockerfile:
console.log("Hello World");
- Redefine the action in action.yml:
name: Hello World on: push: branches: - main jobs: hello: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: "20" - name: Say Hello run: node index.js
Running Docker Image Locally
To build and run the image defined in Dockerfile locally, you need Docker Desktop app. Then, assuming Docker is running locally, you can:
- Build the image:
console.log("Hello World");
- Run it:
name: "Hello World Action" description: "A simple action that says hello" runs: using: "node20" main: "index.js"
3. Cross-Platform Support
Now comes the most interesting part - running your action on other platforms. We'll need to:
- Build and push our Docker image to a registry
- Reference it in platform-specific configurations
Building and Publishing Docker Image
First, create a workflow to build and push the Docker image on every release. We will be using GitHub Container Registry (GHCR) that comes with your GitHub (free for public repositories, 500MB for private repositories on free plan).
name: Use Hello Action on: push: branches: - main jobs: hello: runs-on: ubuntu-latest steps: - name: Say Hello uses: your-username/hello-world-action@main
Github Actions
To use this action in GitHub Actions of another repository, create a workflow file in .github/workflows/hello.yml (see GitHub Actions workflow syntax documentation):
pnpm init # Creates package.json pnpm add -D typescript # Install TypeScript as dev dependency
If you need to run this action on GitHub Actions only, there is no need to build and push the Docker image. GitHub Actions will build the Docker container directly from the Dockerfile specified in your action.yml file on each workflow run. This is more efficient since it avoids the extra steps of pushing to and pulling from a container registry. However, if you plan to use this action on other CI platforms like GitLab or Bitbucket, you'll need to publish the Docker image as shown above.
GitHub's free plan offers the most generous CI/CD minutes allocation among the three platforms. It includes:
- unlimited minutes for public repositories
- 2,000 minutes/month for private repositories
GitLab CI Configuration
Create .gitlab-ci.yml (see GitLab CI/CD documentation):
{ "scripts": { "build": "tsc" } }
Your Gitlab free plan includes 400 CI/CD compute minutes per month regardless if the repository is public or private.
Bitbucket Pipelines
Create bitbucket-pipelines.yml (see Bitbucket Pipelines documentation):
{ "compilerOptions": { "target": "ES2022", "module": "commonjs", "outDir": "./build", "rootDir": "./src", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, "exclude": ["node_modules", "build", "**/*.test.ts"] }
Bitbucket's free plan includes only 50 build minutes per month, regardless if the repository is public or private, making it the lowest free tier of all three platforms.
Other CI/CD Platforms
Since we published our Docker image in a public Github Container Registry, we can run this on any platform that supports Docker images. This is supported by:
- Circle CI (docs)
- Travis CI (docs)
Let me know if you run this somewhere else, I am curious about your use case!
? What can you do with this?
We built an action to run automated Lingo.dev localization for your web and mobile apps on any CI platform. On every commit it updates translations in your entire repository using Lingo.dev localization engine - either as a new commit or by opening a pull request (docs).
Example for GitHub:
console.log("Hello World");
You can build reusable actions and easily integrate them into your workflows regardless of the code hosting platform you are using. Here are some ideas for you:
- cross-platform test reporter (orchestrating end-to-end testing session)
- custom code quality checker (think formatting, linting, testing)
- release notes generator (how about publishing a changelog on your website?)
What would you use it for?
? Bonus: Template repository
If you don't feel like reading the rest of the article, you can find a template starter repository with all the code here. It contains the action - you can run it on GitHub, GitLab and Bitbucket.
https://github.com/mathio/awesome-action-starter
? Tip: Clone the repo and make it a starting point for your own action:
name: Hello World on: push: branches: - main jobs: hello: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: "20" - name: Say Hello run: node index.js…or just create a new repository from my template.
Then just implement your own action logic in src/index.ts file.
Conclusion
We've seen how to evolve from a simple shell-based GitHub Action to a sophisticated TypeScript action that can run anywhere. The key takeaways are:
- Start simple with shell commands to validate your automation logic
- Dockerize your action to make it portable
- Use container registries to distribute your action across platforms
- Adapt the configuration for each platform while keeping the core logic in Docker
This approach gives you the flexibility to run your automation anywhere while maintaining a single codebase. Happy automating!
I occasionally post about tech stuff and new Lingo.dev features on Twitter as @mathio28. Let's keep in touch.
The above is the detailed content of Building Cross-Platform CI/CD Actions with Docker. For more information, please follow other related articles on the PHP Chinese website!

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment
