Skip to content

Commit

Permalink
fix - rework workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
EricThuaud authored May 22, 2024
1 parent a2d1d1f commit 0274aee
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 69 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/ci-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Develop Branch CI - Build release candidate

on:
push:
branches:
- develop

jobs:
check-version:
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.version.outputs.pe-version }}
tag-already-exists: ${{ steps.checkTag.outputs.exists }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get version
id: version
run: echo "pe-version=$(cat package.json | jq -r '.version')-rc" >> $GITHUB_OUTPUT

- name: Print version
run: echo ${{ steps.version.outputs.pe-version }}

- uses: mukunku/[email protected]
id: checkTag
with:
tag: ${{ steps.version.outputs.pe-version }}

- if: ${{ steps.checkTag.outputs.exists == 'true' }}
name: "Skip release"
run: echo "Nothing to tag/release, the release ${{ steps.version.outputs.pe-version }} already exists"

create-release:
needs: check-version
runs-on: ubuntu-latest
if: ${{ needs.check-version.outputs.tag-already-exists == 'false' }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0

- name: Get previous tag
id: previousTag
run: echo "previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep '^[0-9]\+\.[0-9]\+\.[0-9]\+\-rc$' | tail -1)" >> $GITHUB_OUTPUT

- uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.check-version.outputs.release-version }}
target_commitish: ${{ github.head_ref || github.ref }}
name: ${{ needs.check-version.outputs.release-version }}
body: ${{steps.changelog.outputs.changes}}
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-release:
needs: create-release
runs-on: ubuntu-latest
steps:
- name: Extract branch name
shell: bash
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT
id: extract_branch

- uses: actions/checkout@v4
with:
ref: ${{ steps.extract_branch.outputs.branch }}

- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
- run: yarn
- run: yarn build

- name: Upload build
uses: actions/upload-artifact@v4
with:
name: build
path: build
docker:
needs:
- check-version
- build-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Download build
id: download
uses: actions/download-artifact@v4
with:
name: build
path: build

- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: inseefr/platine-my-surveys
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
tags: "latest, ${{ needs.check-version.outputs.release-version }}"
112 changes: 112 additions & 0 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Main Branch CI
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test_lint:
runs-on: ubuntu-latest
if: ${{ !github.event.created && github.repository != 'garronej/ts-ci' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: bahmutov/npm-install@v1
- name: If this step fails run 'yarn lint' and 'yarn format' then commit again.
run: |
yarn lint:check
yarn format:check
test:
runs-on: ${{ matrix.os }}
needs: test_lint
strategy:
matrix:
node: ["16", "18"]
os: [ubuntu-latest]
name: Test with Node v${{ matrix.node }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: bahmutov/npm-install@v1
- run: yarn build
- run: echo "you should replace this line by yarn test (with green test)"

check_if_version_upgraded:
name: Check if version upgrade
# When someone forks the repo and opens a PR we want to enables the tests to be run (the previous jobs)
# but obviously only us should be allowed to release.
# In the following check we make sure that we own the branch this CI workflow is running on before continuing.
if: |
github.event_name == 'push' ||
github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login
runs-on: ubuntu-latest
needs: test
outputs:
from_version: ${{ steps.step1.outputs.from_version }}
to_version: ${{ steps.step1.outputs.to_version }}
is_upgraded_version: ${{ steps.step1.outputs.is_upgraded_version }}
is_pre_release: ${{steps.step1.outputs.is_pre_release }}
steps:
- uses: garronej/[email protected]
id: step1
with:
action_name: is_package_json_version_upgraded
branch: ${{ github.head_ref || github.ref }}

create_github_release:
runs-on: ubuntu-latest
# We create release only if the version in the package.json have been upgraded and this CI is running against the main branch.
# We allow branches with a PR open on main to publish pre-release (x.y.z-rc.u) but not actual releases.
if: |
needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' &&
(
github.event_name == 'push' ||
needs.check_if_version_upgraded.outputs.is_pre_release == 'true'
)
needs:
- check_if_version_upgraded
steps:
- uses: softprops/action-gh-release@v1
with:
name: Release v${{ needs.check_if_version_upgraded.outputs.to_version }}
tag_name: v${{ needs.check_if_version_upgraded.outputs.to_version }}
target_commitish: ${{ github.head_ref || github.ref }}
generate_release_notes: true
draft: false
prerelease: ${{ needs.check_if_version_upgraded.outputs.is_pre_release == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
needs: check_if_version_upgraded
if: |
needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' &&
(
github.event_name == 'push' ||
needs.check_if_version_upgraded.outputs.is_pre_release == 'true'
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- uses: actions/setup-node@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
context: .
push: true
tags: |
inseefr/platine-my-surveys:${{ needs.check_if_version_upgraded.outputs.to_version }}
inseefr/platine-my-surveys:latest
68 changes: 0 additions & 68 deletions .github/workflows/ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "platine-my-surveys",
"version": "0.2.22",
"version": "0.2.23",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.0",
Expand Down

0 comments on commit 0274aee

Please sign in to comment.