How to keep fork master branch in sync with azerothcore master branch - azerothcore

How can I automatically keep my fork master branch in sync with the AzerothCore master branch?

You can use GitHub Actions to keep your fork master branch in sync:
on:
schedule:
- cron: "0 */6 * * *"
jobs:
repo-sync:
runs-on: ubuntu-latest
steps:
- name: repo-sync
uses: wei/git-sync#v2
with:
source_repo: "https://github.com/azerothcore/azerothcore-wotlk.git"
source_branch: "master"
destination_repo: "https://${{ secrets.GH_USERNAME }}:${{ secrets.GH_TOKEN }}#github.com/${{ secrets.GH_USERNAME }}/azerothcore-wotlk.git"
destination_branch: "master"
Create the secrets in the fork repo settings. You can refer here on how to add them:
https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository
In my case I created the secrets GH_USERNAME and GH_TOKEN
GH_USERNAME should be set to your github username.
GH_TOKEN should be set to a personal access token that you create.
Refer here for information on how to create one:
https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token

Related

How to disable running builds on commit for a gitrepo resource

I have a git repo resource, but I don't want to trigger run on every commit into this repository. is there anyway I can achieve this?
We should disable buildOn Commit here. for example,
- name: my_app_repo
type: GitRepo
configuration:
gitProvider: my_github
path: myuser/repo-name
branches:
include: master
buildOn:
commit: false
Reference

GitHub Actions Trigger Publish Job Only When Releasing a Package

I have a Scala based multi module project for which I'm having a GitHub Actions pipeline which contains two jobs, one for test and the other for publishing to GitHub packages. Here is my file:
name: Build my projects
on:
push:
paths-ignore:
- 'images/**'
- README.md
branches:
- master
tags:
- 'v*.*.*'
pull_request:
branches:
- master
release:
types: [ created ]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
- uses: actions/checkout#v2
- name: Cache ivy2
uses: actions/cache#v1
with:
path: ~/.ivy2/cache
key: ${{ runner.os }}-sbt-ivy-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
- name: SBT Test
run: sbt clean test
publish:
needs: test
steps:
- name: Checkout
- uses: actions/checkout#v2
- name: SBT Publish
run: sbt publish
I would need the following:
Trigger the publish job only when I want to do a release, but how do I know that I want to do a release? Do I tag a release when I commit the changes? If I tag it, then how can I check if there is a tag so that I know that I have to run the publish job?
If you want to trigger a workflow "only when you want to do a release", one option is to manually launch the workflow.
This can be achieved with a specific workflow with following trigger workflow_dispatch:
on:
workflow_dispatch:
inputs:
releaseVersion:
description: 'Release version'
required: true
Here I add an input value that has to be entered manually when launching the workflow. This is not mandatory though if you don't need any input.
See also: https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
Note that triggering the workflow when a tag is pushed is also a solution that makes sense. It's really up to you.
I just had to do this in the publish job:
publish:
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags/v')
So when there is a tag, the publish job knows that it has to run and publish the new package.

Github Actions - How can I make my env variable(stored in .env file) available in my workflow

I'll try to be as clear as possible. I have also asked about related issues but didn't receive a convincing response.
I'm using React and firebase for hosting.
Also, I'm storing my firebase web API key in my .env file.
I set up firebase hosting using Firebase CLI and chose to automatically deploy on merge or pull request.
After the setup finished a .github folder with .yml file was created in my working directory.
.github
- workflows
-firebase-hosting-merge.yml
-firebase-hosting-pull-request.yml
So now when I deploy my project(without pushing to GitHub) manually to firebase by running firebase deploy everything works fine and my app is up and running.
However when I make changes and push my changes to Github. Github actions are triggered and the automatic deployment to the firebase process starts. The build passes all the checks. However, when I visit the hosted URL there is an error I get in the console saying Your API key is invalid, please check you have copied it correctly.
I tried few workarounds like storing my firebase web API key into the Github secrets and accessing it in my .yml file.
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- master
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: npm ci && npm run build --prod
- uses: FirebaseExtended/action-hosting-deploy#v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_EVENTS_EASY }}'
channelId: live
projectId: my-project
env:
REACT_APP_API_KEY: ${{secrets.REACT_APP_API_KEY}}
FIREBASE_CLI_PREVIEWS: hostingchannels
But I am still getting the error. I feel that the error is definitely due to the environment variables.
I have stored my firebase web API key in my .env.production file located in the root directory.
Somehow GitHub actions are not using my environment variables defined.
Please let me know how can I manage my env variables so that it can be accessed by my workflow.
The answer is put custom env vars in first level before jobs:
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- master
env: # <--- here
REACT_APP_API_KEY: ${{secrets.REACT_APP_API_KEY}} # <--- here
jobs:
build_and_deploy:
...
And add this secrets in Github > Your project > Settings > Secrets
You can use Create Envfile Github Action to create a .env file in your workflow.
To add a key to the envfile, add a key/pair to the with: section. It must begin with envkey_.
steps:
- uses: actions/checkout#v2
- name: Use Node.js
uses: actions/setup-node#v1
- name: Make envfile
uses: SpicyPizza/create-envfile#v1
with:
envkey_REACT_APP_API_KEY: ${{secrets.REACT_APP_API_KEY}}
directory: './'
file_name: '.env'

Github actions replacing firebase json in flutter project

I'm running a Github action that automatically builds and releases a flutter project. But we use a dev and a production Firebase environment. so before the build I'd like to switch out the google-services.json from the dev to the production version. But I can't seem to find an easy way to do this. Or is there a better way to work with dev and production versions of Firebase inside flutter?
probably not very useful but here's the action in it's current state
on:
push:
branches: [ stable ]
name: Build and Release
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
with:
fetch-depth: '0'
- name: Bump version and push tag
id: tag
uses: anothrNick/github-tag-action#1.17.2
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
WITH_V: true
RELEASE_BRANCHES: stable
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
flutter-version: '1.17.3'
- run: flutter pub get
- run: flutter build appbundle
- name: Create a Release APK
uses: ncipollo/release-action#v1
with:
artifacts: "build/app/outputs/bundle/release/*.aab"
tag: ${{ steps.tag.outputs.tag }}
token: ${{ secrets.TOKEN }}
I'm very, very new to github actions and CI in general. any constructive feedback is always welcome!
Not sure that's the most optimised solution but it's what I found being the easiest to update and maintain.
Step 1 : Store the google-services.json files in the secrets of your Github repository (that way you won't have to commit this file in your repo, that's a bonus) with names like FIREBASE_CONFIG_DEV and FIREBASE_CONFIG_PROD.
Step 2 : Create two workflows : one for the dev, triggered every pull-request for example, and the other one for the release, triggered by a commit on a specific branch like your did
Step 3 : Provide the google-service.json to your project
steps:
- uses: actions/checkout#v1
- name: Provide Firebase Android
env:
FIREBASE_CONFIG_DEV: ${{ secrets.FIREBASE_CONFIG_DEV }}
run: echo $FIREBASE_CONFIG_DEV > ./android/app/google-services.json
Your Dev workflow should look like this
Just edit this snippet to add the creation of the google-services.json to your iOS project and you should be good to go

How can I set up a Bitbucket and SonarCloud integration for a Xamarin.Forms project?

Disclaimer: I do have almost no knowledge with DevOps, containers and CI/CD pipelines and it's something I'm learning on the fly.
I currently have a private Xamarin.Forms project hosted on Bitbucket, and I've created a SonarCloud account that I want to use to analyze the code within Bitbucket. From what I was able to gather from the SonarCloud onboarding process I need to setup a build pipeline within Bitbucket.
This is a code snippet of what SonarCloud says that I need to use within the bitbucket-pipelines.yml file:
image: ************************** # Choose an image matching your project needs
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- ************************** # See https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html
- sonar
script:
- ************************** # Build your project and run
- pipe: sonarsource/sonarcloud-scan:1.0.1
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.3
pipelines: # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
branches:
master:
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
pull-requests:
'**':
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
I've read and re-read the https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html article, but I wasn't ablet to gather much information. Seems like a rabbit hole with links to another articles that don't seem like they will be able to get me where I need.
So, a the moment my major doubts are:
Can a Bitbucket pipeline build Xamarin.Forms projects? (Android and iOS)
If so, how can I set up a bitbucket-pipelines.yml in order to allow that?
If not, should I go to Azure Devops or some other platform that will allow me to do that and integrate with SonarCloud?
I'm already using Visual Studio App Center to build the Android and iOS app (integraged with Bitbucket). But it seems like the AppCenter can't be natively integrated with SonarCloud.
Can anyone help me with that?
Attaching a sample working bitbucket-pipelines.yml file for reference
image: node:10.15.0 # Choose an image matching your project needs
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- node # See https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html
- sonar
script:
- npm install
- pipe: sonarsource/sonarcloud-scan:1.2.0
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.4
pipelines: # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
custom: # defines that this can only be triggered manually or by a schedule
staging: # The name that is displayed in the list in the Bitbucket Cloud GUI
- step:
script:
- echo "Scheduled builds in Pipelines are awesome!"
- step:
name: Build, test and analyze on SonarCloud
caches:
- node # See https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html
- sonar
script:
- pipe: sonarsource/sonarcloud-scan:1.2.0
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.4
branches:
master:
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
pull-requests:
'**':
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
Pipeline file is used to create a small container in bitbucket infrastructure and runs the code analysis there.
This file provides information regarding
When all checks should run
What all checks should be done.
Configuration of the image and container which will be created to run the pipeline.
Cache configuration for faster builds.
Reusable build-level code components like steps etc.
bit bucket docs for reference
https://support.atlassian.com/bitbucket-cloud/docs/get-started-with-bitbucket-pipelines/
https://support.atlassian.com/bitbucket-cloud/docs/pipeline-triggers/
https://support.atlassian.com/bitbucket-cloud/docs/use-docker-images-as-build-environments/
https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/

Resources