I am trying to understand how gatsby works with netlify and yarn develop.
My current workflow:
Start gatsby (yarn develop)
Login in at http://localhost:8000/admin/
Create a new element ==> this gets committed to my github.com repo perfectly
Problem:
When developing, I need the new element also in my cloned repo. Sure, I can git pull all day but isn't there an easier solution?
config.yml:
backend:
name: 'github'
repo: 'my-name/my-repo'
branch: 'main'
api_root: 'https://api.github.com'
Related
I have a repo which attempts to serve an index.html file using
the NPM serve module in a GitHub action.
Here's what the action looks like (.github/workflows/deploy.yml):
name: test-serve-deploy
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout#v3
- run: echo "Clone complete"
- name: install
run: |
npm install
- name: serve
run: |
npm run serve
- run: echo "Status ${{ job.status }}"
I understand that the content in my repo is just an index.html file and could be served statically with GitHub Pages, but this is just a test repo I'm using to understand how GitHub actions work.
When the action runs, it predictably hangs on the npm run serve:
However, this URL returns a 404: http://jonbri.github.io/test-serve:3000
I'm sure I'm missing something fundamental about how these actions/runners work.
My goal is to have the GitHub repo not only deploy but also serve a Node.js app.
What steps would I need to take to get this working?
Github runners are ephemeral. They just run the commands you provide and exit.
They cannot serve pages. If you want to serve content, you might want to use your github runner to deploy your content to a provider such as netlify or aws s3, lambda etc.
I have added a homepage, predeploy and deploy properties to my package.json file, linked my app to my github and ran npm run deploy. The terminal indicates success, then when I go to my Gitpages URL I get the following: https://joe-dp.github.io/mh-app/
Does anyone have any ideas why the link is redirecting me to a React information page?
Under Repo → Settings → Pages → Sources, and select the gh-pages branch
Put your built application (e.g. dist) at the root of the gh-pages branch to be served up
You'll probably want to automate this, which can be done quite easily with GitHub Actions.
The following example, uses JamesIves/github-pages-deploy-action, to build an deploy your app every time a change is made on your main branch.
Just create a file in .github/workflows/deploy-gh-pages.yml in your main branch, then populate it with:
name: Build and Deploy to GH Pages
on:
push:
workflow_dispatch:
permissions:
contents: write
jobs:
build-and-deploy:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Install and Build
run: |
yarn
yarn build
- name: Deploy
uses: JamesIves/github-pages-deploy-action#v4.3.3
with:
branch: gh-pages
folder: dist
Commit your files, the action will run automatically, and a few minutes later your app will be live on GH Pages 🚀
If you'd like to see a real-world example of this, I'm doing something similar in this project.
I'm trying to create a pipeline on Gitlab CI that increments the app version everytime we get a commit on master. But it is ignoring my ci.skip command and I don't know why.
The yaml file is this one:
.gitlab-ci.yml
workflow:
rules:
- if: $CI_COMMIT_BRANCH == 'master'
before_script:
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git remote set-url origin https://push:$PUSH_KEY#$CI_SERVER_HOST/$CI_PROJECT_PATH.git
auto_release:
image: node:10
script:
- yarn
- yarn release
- git push --follow-tags origin HEAD:master -o ci.skip
- echo "Done!"
So everytime I push a new commit it gets locked inside an eternal loop that commits a new version and commits a new version over and over again. The only way to stop is manually cancelling the jobs.
Pleas note: When we use the image node or node:latest it works, but our version requires node:10 otherwise it will break and won't build.
node:10 is a very old image. The git version it contains does not support push options (at least with the shorthand -o), so that's why the push triggers the next CI build.
Check the git version in the image - if it's 2.10 to 2.17 you can use --push-option=ci.skip. If it's still an older version, you need to create your own docker image that contains node version 10 and a modern git version.
I am creating a GitHub Actions workflow to build and publish npm packages to GitHub Packages. The repo is a monorepo with several packages, so I am using the semantic-release-monorepo tool. However, the step to publish is failing and I can't figure out why.
My GitHub Actions workflow file is as follows (trimmed down slightly)
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
GH_TOKEN: ${{ secrets.MY_PAT }}
steps:
- name: Checkout repo
uses: actions/checkout#v2
run: |
yarn install
yarn build
- name: Setup node for publishing to Github packages
uses: actions/setup-node#v2
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
node-version: "12.x"
registry-url: "https://npm.pkg.github.com"
- name: Yarn publish packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
yarn publish-packages
yarn publish-packages runs a script which executes the lerna command for semantic release
lerna exec --concurrency 1 -- npx --no-install semantic-release -e semantic-release-monorepo
I have made sure the repo package.json as well as the package.json for every package has the correct repository url, https://github.com/owner/repo.git. My personal access token has permissions to repo and write and delete packages.
No matter what configs I change, the step fails with the following messages:
The command "git push --dry-run --no-verify
https://[secure]#github.com/xxx/xxx.git HEAD:develop"
failed with the error message remote: Repository not found. 26 fatal:
repository 'https://github.com/xxx/xxx.git/' not found.
The second message is
EGITNOPERMISSION: 'semantic-release cannot push the version tag to
the branch develop on the remote Git repository with URL
https://[secure]#github.com/xxx/xxx.git
Other things I have tried:
Adding scope="#xxx" to the setup-node step after reading GH docs that says "GitHub Packages only supports scoped npm packages"
According to semantic-release docs, I have tried setting GH_TOKEN, GITHUB_TOKEN and NPM_TOKEN to every combination of my PAT or the GITHUB_TOKEN in secrets. I believe the docs say only PAT is supported. Also, NPM_TOKEN should not be required because using registry-url with the setup-node action creates an .npmrc file that uses NODE_AUTH_TOKEN by default.
There is an almost similar question here but adding .git to his repository url seems to have fixed it for him
Github docs say that I should be able to use a PAT or the GITHUB_TOKEN as the auth token in the .npmrc file, so that shouldn't be the issue
I've looked through the docs for semantic-release, semantic-release-monorepo, GitHub Actions, and GitHub Packages. If there is any additional information I need to include please let me know.
After some more trial and error, I discovered the cause. If my understanding is correct, a Github workflow will automatically use the available GITHUB_TOKEN secret to authenticate with Github during the step to checkout the repo using actions/checkout. It was then persisting the credentials from this step and reusing them for the step to publish packages, even though I was injecting a personal access token as an environment variable to that step.
In the end, the fix was to use the persist-credentials option in step one like this
steps:
- name: Checkout repo
uses: actions/checkout#v2
with:
persist-credentials: false
And then using the personal access token to authenticate with GitHub in the last step like I noted I believed should be the correct method in my question, as semantic-release docs state only PAT authentication is supported.
I have a node.js website that runs locally fine with node server.js. I added a Dockerfile:
FROM node:carbon
VOLUME ["/root"]
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
And if I deploy my app with gcloud app deploy I can get it accessible online via a url. I believe my project is an 'App Engine' project? If I run subsequent gcloud app deploy commands, my new code gets pushed to the online site. But I can't get github master commits trigger and publish a new build.
I tried adding a trigger so that everytime new code gets added to my public github repo master branch, it gets sent to my production URL.
Full Trigger:
So I merge a PR into the master branch of my github repo. I look in my build history and see there is a new build, clicking the commit takes me to the new pr I just merged into the master branch of my github repo.
But If I access my website url, the new code is not there. If I run cloud app deploy again eventually it will appear, my trigger seems to be working fine from the logs, why is my build not getting published?
I think the problem might be with the fact that you're using a Dockerfile instead of Cloud Build configuration file... Unless there's something else I'm not seeing.
Look here under the fourth step, fifth bullet, for the solution. It says:
Under Build configuration, select Cloud Build configuration file.